Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript Regex negative lookbehind Alternative

Looks like it is not first question about look-behind, but I didn't find an answer.

Javascript has no (positive|negative)look-behind requests.

I need a regular expression that match *.scss file name, but didn't match the names like *.h.scss. With look-behind request is looks like:

/(?<!(\.h))\.scss$/

How can I do this in javascript? I need this regular expression for webpack rules "test" parameter, so the javascript regex required only.

like image 249
Jonik Avatar asked Jan 03 '23 20:01

Jonik


1 Answers

You may use

/^(?!.*\.h\.scss$).*\.scss$/

See the regex demo

Details

  • ^ - start of string anchor
  • (?!.*\.h\.scss$) - a negative lookahead failing the match if the string ends with .h.scss
  • .* - any 0+ chars as many as possible
  • \.scss - a .scss substring at the...
  • $ - end of the string.
like image 171
Wiktor Stribiżew Avatar answered Jan 13 '23 18:01

Wiktor Stribiżew