问题
I'm trying to match some strings of the pattern:
event = sometext1 name = prefix sometext2
I want to match all cases that sometext1 and sometext2 are different. How should I do it with regular expression? Thanks!
回答1:
You can use this regex:
event += +(\w+) +name+ = +\w+ +((?!\1)\w+)\b
RegEx Demo
回答2:
Use a backreference like this:
^event = ([^\s]+) name = prefix (?!\1).+$

Debuggex Demo
来源:https://stackoverflow.com/questions/28889304/regular-expression-match-and-compare-captured-groups