0

I want to match everything except this

/^_.*\.scss$/i

I tried this

/^(?!_.*\.scss).*$/i

but it did not match on

_dsdfsdfsdf.scss.sd

I think its because the regex says you only can't start with that. But in this case, it should match this.

How can this be fixed?

omega
  • 40,311
  • 81
  • 251
  • 474
  • Add an end-of-string anchor `$`? Rather, why didn't you include it in the lookahead in the first place? It was already present in the original regex... – Aran-Fey Apr 03 '18 at 22:07
  • What do you mean? I do have it on the regex. – omega Apr 03 '18 at 22:07
  • Actually this worked `/^(?!_.*\.scss$).*$/i` – omega Apr 03 '18 at 22:10
  • It should be inside of the lookahead. Why did you put everything _except_ the `$` into the lookahead? Of course it doesn't work correctly if you only negate a part of your regex instead of the whole thing. – Aran-Fey Apr 03 '18 at 22:10
  • Why do you need to negate the match inside of the regex? Why not just `if (!/\.scss$/i.test(str))`? – melpomene Apr 03 '18 at 22:15

0 Answers0