Reputation: 13907
So I'm trying to write a JavaScript variable-highlighting regular expression, so that variable declaration names are highlighted by the following code:
var foo = 'bar',
raz = 'zar',
wat
So far I have a regexp that whichights foo
and raz
but not wat
since the regexp works by ending with the =
character.
(var|,)(.*?)=
How can I modify this regexp so that is also highlights wat
?
I have a feeling that the missing piece is to swap the =
with an ending word boundary match.
Upvotes: 2
Views: 7706
Reputation: 785156
Can you try this regex:
(?:var|,)\s*(\w+)(?= *=|$)
Upvotes: 1