I’m trying to find a regex that will match a specific expression in the following format:
name = value
However, I need it to not match:
name.extra = value
I have the following regex:
([\w\@\-]+) *(\=|\>|\>\=|\<|\<\=) *([^\s\']+)
which matches the first expression, but also matches the second expression (extra = value).
I need a regex that will match only the first expression and not the second (i.e. with a dot).
Negative lookbehind assertion (
?<!) might be what you are looking for.For a simple assignment:
(?<!\.)\b(\w+)\s*=\s*(\w+)summary:
(?<!\.)= prevent the character.at that location\b= beginning of a wordThe captured words are:
and using the regex you specified, this should give something near this:
(?<!\.)\b([\w\@\-]+) *(\=|\>|\>\=|\<|\<\=) *([^\s\']+)