Regular Expression Match And Compare Captured Groups

旧时模样 提交于 2021-01-29 02:27:21

问题


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).+$

Regular expression visualization

Debuggex Demo



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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!