Reputation: 989
With regex, I'd like to make sure all variables are defined.
So the regex should match all strings (whatever the number of spaces) that are followed by an equal sign and are not followed by any character on that line. But the equal sign can be followed by spaces, tabs anything other than characters.
Here's the opposite of what I'd like to get: ([^\s]+).*=.*([,\S]+)
// SELECT THESE ONES
const okOne =
const okTwo=
okThree=
var okFour=
// DON'T GET THESE ONES
const badOne = "badOne"
const badTwo= "badTwo"
badThree=3
var badFour=$s
Upvotes: 2
Views: 53
Reputation: 14678
Very simple, try the following; ^.*=\s*$
Within each line ^$
, starts with anything up to an equal sign .*=
, should have nothing but empty space or just nothing till the end of line \s*
Upvotes: 2
Reputation: 163217
You could match any character non greedy until the first equals sign. Then match 0+ times a space or a tab.
^.*?=[ \t]*$
Explanation
^
Start of the string.*?
Match any character non greedy=
Match literally[ \t]*
Character class which matches 0+ times a space or a tab$
End of the lineUpvotes: 1
Reputation: 1673
Try this: ^.*?=\W*$
It will match anything before the equal sign (non greedy), then =
and then any non-character (\W
).
Upvotes: 2