可以使用RegEx比较两个捕获的组 [英] Can use RegEx to compare two captured groups

查看:60
本文介绍了可以使用RegEx比较两个捕获的组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条日志消息,仅当两个捕获的组相同时才想匹配!例子

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

除了某个日期之外,源ip = 1.1.1.1中的某个日期试图将其他数据发送到目的地ip = 1.1.1.1

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

所以,如果sip = dip匹配,我想触发!可以使用单个正则表达式吗?

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

推荐答案

是的,可以通过反向引用来完成. https://www.regular-expressions.info/backref.html

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

使用除了某些日期之外,源ip = 1.1.1.1中的某个日期试图将其他数据发送到目的地ip = 1.1.1.1"作为输入:

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)

这篇关于可以使用RegEx比较两个捕获的组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆