Reputation: 1516
I was reading the source code of lex of coffeescript, and I got below regex for IDENTIFIER
IDENTIFIER = /^([$A-Za-z_\x7f-\uffff][$\w\x7f-\uffff]*)([^\n\S]*:(?!:))?/;
Just not sure why (?!:) is required though I know it is a non-capturing negative lookahead group
Upvotes: 0
Views: 34
Reputation: 1074238
It requires that the match not be followed by a second :
. Without it, the match could be followed by a second :
. So with that negative lookahead, given the input foo::
, only foo
matches; without it there, given the input foo::
, foo:
(with the colon) matches. You can play with it over on regex101.
Upvotes: 1