Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the regular expression, /(?!^)/g mean?

Tags:

What does the regular expression, /(?!^)/g mean?

I can see that from here x(?!y): Matches x only if x is not followed by y.

That explains, if ?! is used before any set of characters, it checks for the not followed by condition.

But we have, ?!^. So, if we try to say it in words, it would probably mean not followed by negate. That really does not make me guess a probable statement for it. I mean negate of what?

I'm still guessing and could not reach a fruitful conclusion.

Help is much appreciated.

Thanks!

like image 616
devGeek Avatar asked May 24 '18 08:05

devGeek


1 Answers

Circumflex ^ only implies negation in a character class [^...] (when comes as first character in class). Outside of it it means start of input string or line. A negative lookahead that contains ^ only, means match shouldn't be found at start of input string or line.

See it in action

like image 101
revo Avatar answered Sep 28 '22 17:09

revo