正则表达式匹配字符串中的重复数字

huangapple go评论64阅读模式
英文:

Regex to match for repeating numbers in a string

问题

我只想挑选出具有重复数字的行。

Col A
100,100,100,100,100,100,100,100,100,100,100
3,61,3,145,61,61,61,61
299,295,299.5,300,299.5,299
5.98,5.98,397.56,405.51,398.53,7.95,405.51,405.51,398.53
482.14,1522.12,1001.92,1990.39,1000,1999.79
649.36,610.4,1136.75,626.78,590.34
2284.58,1773.35,2169.48,1760.41,1256.36
2979.55,3032.63,3023.23,2505.15
431,154.5,179
302.95,304,304
339.96,159.27,340.74,160.04,153.46,346.54
170,170,170
968.41,8.86,486.5,360.4,102.64
420,500,500
200,250,250

使用正则表达式匹配具有重复数字的行。

  1. 它们也可以由不匹配的数字分隔开。
英文:

I have a column like this, I only want to pick rows with repeating numbers

Col A
100,100,100,100,100,100,100,100,100,100,100
3,61,3,145,61,61,61,61
299,295,299.5,300,299.5,299
5.98,5.98,397.56,405.51,398.53,7.95,405.51,405.51,398.53
482.14,1522.12,1001.92,1990.39,1000,1999.79
649.36,610.4,1136.75,626.78,590.34
2284.58,1773.35,2169.48,1760.41,1256.36
2979.55,3032.63,3023.23,2505.15
431,154.5,179
302.95,304,304
339.96,159.27,340.74,160.04,153.46,346.54
170,170,170
968.41,8.86,486.5,360.4,102.64
420,500,500
200,250,250

regex match for rows that have repeating numbers

  1. they can be seperated by non matching numbers as well

答案1

得分: 1

使用捕获组来捕获每个数字,并使用反向引用来匹配数字的重复。

\b(\d+(?:\.\d+)?)\b.*\b\b

示例

英文:

Use a capture group to capture each number, and a back-reference to match a repeat of the number.

\b(\d+(?:\.\d+)?)\b.*\b\b

DEMO

huangapple
  • 本文由 发表于 2023年6月8日 14:30:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/76429144.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定