开发者

regex for matching where parts of string are not same

开发者 https://www.devze.com 2023-03-19 22:46 出处:网络
I\'ve got something like this stuff(123)=stuff(123) stuff(23434)=stuff(234324) I want to match all instances where the right hand side and left hand side differ.

I've got something like this

stuff(123)=stuff(123)
stuff(23434)=stuff(234324)

I want to match all instances where the right hand side and left hand side differ.

I've got this but it doesn't seem to work:

\\(stuff([0-9]+)\\)=[^\\1]

Also, I开发者_运维技巧'm trying to do this using emacs regex search.


Based on your answer to my comment, I'd use flush-lines:

M-x flush-lines RET \(stuff([0-9]+)\)=\1 RET

Note that you only use single backslashes at the miniprompt


if(false==foo.match(/(stuff\([0-9]+\))=\1/) is the sort of thing you want. Depends on your regex dialect. You can't [^\\1], [] is a character class.

You may want to look into zero-width assertions. Again, it depends on your dialect.

0

精彩评论

暂无评论...
验证码 换一张
取 消