[英]Regex to match multiple occurrences of pattern and disregard content in-between
I am trying to match multiple occurrences of a pattern in a string and disregard the in-between content.我试图匹配字符串中多次出现的模式并忽略中间的内容。
For example, in the string below:例如,在下面的字符串中:
"35264208011:5:1044512:0.1078, 1044512:6:3526415811:0.0444, 699905011:6:3526420011:0.0544”
I want to get all the occurrences of 1044512
and their accompanied rate (ie value with the decimal)我想获得
1044512
所有出现及其伴随率(即带小数的值)
My desired output would be: "1044512:0.1078, 1044512:0.0444"
我想要的输出是:
"1044512:0.1078, 1044512:0.0444"
I have tried '1044512:(.*?)0\\0000' but seems to be missing something significant.我试过 '1044512:(.*?)0\\0000' 但似乎缺少一些重要的东西。 Any help is much appreciated.
任何帮助深表感谢。
try this regex :试试这个正则表达式:
(1044512)(?:.*?)(0\.\d*)
in your example this will give you this matches :在您的示例中,这将为您提供以下匹配项:
match 1 : 1044512:0.1078
group 1 : 1044512
group 2 : 0.1078
match 2 : 1044512:6:3526415811:0.0444
group 1 : 1044512
group 2 : 0.0444
then all what you need to do is to concatenate group 1 with group 2 like this :那么您需要做的就是像这样将第 1组与第 2 组连接起来:
$1:$2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.