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.
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.
Share Improve this question asked Feb 10, 2018 at 23:05 JonikJonik 1,2592 gold badges12 silver badges20 bronze badges 2- can someone please answer following: stackoverflow./q/59403483/11264185 – Shivam Poojara Commented Dec 19, 2019 at 6:51
- See also stackoverflow./q/641407 – cmbuckley Commented Dec 19, 2019 at 11:46
2 Answers
Reset to default 6You 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.
You can list all possible subpatterns that doesn't match .h
and build an alternation:
/(?:[^.].|\.[^h]|^.?)\.scss$/