最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript Regex negative lookbehind Alternative - Stack Overflow

programmeradmin1浏览0评论

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
Add a ment  | 

2 Answers 2

Reset to default 6

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.

You can list all possible subpatterns that doesn't match .h and build an alternation:

/(?:[^.].|\.[^h]|^.?)\.scss$/
发布评论

评论列表(0)

  1. 暂无评论