过滤正则表达式为百分比

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

filter regex to percentage

问题

在Case 1中,您可以使用以下正则表达式来过滤超过8%的百分比,示例:Increased % 8.05

Increased % (?:[89]\.\d+|\d{2,}\.\d+)

在Case 2中,您可以使用以下正则表达式来过滤超过10%的百分比,示例:Increased % 12.05

Increased % (?:10\.\d+|1[1-9]\.\d+)
英文:

I would like two examples of regular expression to filter percentage:

I have the following cases:

Case 1:

Increased % 3.05
Increased % 8.05
Increased % 12.05

Case 2:

Increased % 3.05
Increased % 8.05
Increased % 12.05

In case 1, I would like a regular expression to filter any percentage above 8%, example: Increased % 8.05
In case 2, I would like a regular expression to filter any percentage above 10%, example: Increased % 12.05

Any idea how to assemble a regex string for case 1 and case 2?

I don't have much knowledge in regex and all the alternatives I tested didn't come close to the expected result.

答案1

得分: 0

要过滤超过10%的内容:

^.*%\s*[1-9]\d+(?:\.\d+)?

正则表达式演示

[1-9]\d+(?:\.\d+)? -> 匹配19和一个或多个数字 + 可选的小数部分


要过滤超过8%的内容:

^.*%\s*(?:8|\d\d+)(?:\.\d+)?

正则表达式演示

(?:8|\d\d+)(?:\.\d+)? -> 匹配8或两个或更多数字 + 可选的小数部分

英文:

To filter above 10%:

^.*%\s*[1-9]\d+(?:\.\d+)?

Regex demo.

[1-9]\d+(?:\.\d+)? -> matches 1 to 9 and one or more digits + optional decimal part


To filter above 8%:

^.*%\s*(?:8|\d\d+)(?:\.\d+)?

Regex demo.

(?:8|\d\d+)(?:\.\d+)? -> matches 8 or two or more digits + optional decimal part

huangapple
  • 本文由 发表于 2023年2月27日 08:07:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/75575802.html
匿名

发表评论

匿名网友

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

确定