Question: how to match any word that is not preceded by .
?
In the context of a code syntax highlighter, unlike: Negative lookbehind equivalent in JavaScript, I don't want to reverse string then combine with lookahead nor reverse the matches order (like $1$0) since I concat multiple regex with |
, nor use XRegExp, nor use string delimiters ^
, $
, .
.
With PCRE I would simply do: /(?<!\.)\b[a-z]\w+/gi
As I keep forgetting how to simply solve this out I would like to know if there is a recurrent pattern I can remember for mimicking negative look-behinds in JavaScript. Using look-ahead and reversing the matching logic always gets me dizzy!
Also most answers in SO use string delimiters, so it's not the same difficulty.
This is the closest I got: /((?!\.) )\b[a-z]\w+/
, https://regex101.com/r/9hw2Y2/1, but it matches a one length char before my match (can see in green with PCRE flavor selected).