问题
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