我有以下文字:
instance=hostname1, topic="AB_CD_EF_12345_ZY_XW_001_000001"
instance=hostname2, topic="AB_CD_EF_1345_ZY_XW_001_00001"
instance=hostname1, topic="AB_CD_EF_1235_ZY_XW_001_000001"
instance=hostname2, topic="AB_CD_EF_GH_4567_ZY_XW_01_000001"
instance=hostname1, topic="AB_CD_EF_35678_ZY_XW_001_00001"
instance=hostname2, topic="AB_CD_EF_56789_ZY_XW_001_000001"
我想从上面的示例中获取数字。我尝试使用下面的正则表达式来做到这一点,它们可以很好地用作单独的查询:
Regex: *.topic="AB_CD_EF_([^_]+).*
Matches: 12345 1345 1235
Regex: *.topic="AB_CD_EF_GH_([^_]+).*
Matches: 4567 35678 56789
但是我需要一个可以给我所有数字的正则表达式,即:
12345 1345 1235 4567 35678 56789
请您参考如下方法:
将GH_
设为可选:
.*topic="AB_CD_EF_(GH_)?([^_]+).*
匹配您的所有目标数字。
参见 live demo。
通过使用以下任意数量的“字母下划线”序列,您可能会更通用:
.*topic="(?:[A-Z]{2}_)+([^_]+).*
参见 live demo。