Can use RegEx to compare two captured groups

十年热恋 提交于 2021-01-29 09:01:27

问题


I have a log message that i want to match only if two captured groups are the same! example

some date from source-ip=1.1.1.1 trying to send another data to the destination-ip=1.1.1.1 in addition to some date

So, i want to trigger if sip=dip it matches!? Would it be possible using a single regex?


回答1:


Yes, this can be done via back-references. https://www.regular-expressions.info/backref.html

Using "some date from source-ip=1.1.1.1 trying to send another data to the destination-ip=1.1.1.1 in addition to some date" as input:

(\d+\.\d+\.\d+\.\d+).*(\1)


来源:https://stackoverflow.com/questions/49801715/can-use-regex-to-compare-two-captured-groups

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