[英]mysql regex - filter for a number greater than XX when followed by a specific string
Im searching for a RegEx that I can use in my MySql Query我正在寻找可以在 MySql 查询中使用的 RegEx
What I want to archive is a query that filters all rows where there is a string with the the value "xx% to Fire Resistance" while xx is a dynamic value , lets say 22 , but I dont just want all rows with 22 but all rows with 22 AND higher .我想要存档的是一个查询,它过滤所有行,其中有一个值为 "xx% to Fire Resistance" 的字符串,而 xx 是一个动态值,比如说 22 ,但我不只是想要所有带有 22 的行,而是所有行具有 22 和更高的行。 Is that somehow possible ?这有可能吗?
I could filter it in a second step with php, but the initial result would be way to big to be practical to work with.我可以在第二步用 php 过滤它,但最初的结果将是大到实用的方式。
What I currently have (and does not rly work because it just filters for a number before the given string)我目前拥有的(并不能正常工作,因为它只是在给定字符串之前过滤一个数字)
SELECT * FROM items WHERE `mods` REGEXP '\b(\d+(?:\.\d+)?)% to Fire Resistance\b'
What I would need in theory理论上我需要什么
SELECT * FROM items WHERE `mods` REGEXP '\b(\d+(?:\.\d+)?)% to Fire Resistance\b' > 22
one example "mods" field content一个示例“mods”字段内容
Some more text;+170 to Accuracy Rating;+25% to Fire Resistance;+4 to Armour;+6 to Evasion Rating;+43 to maximum Life;+39% to Lightning Resistance;Some more text;Some more text;
https://regex101.com/r/ZhIMzc/2 https://regex101.com/r/ZhIMzc/2
In MySQL versions before 8, you may use在 MySQL 8 之前的版本中,您可以使用
REGEXP '[[:<:]](2[2-9]|[3-9][0-9]|[1-9][0-9]{2,})([.][0-9]+)?% to Fire Resistance[[:>:]]'
Details细节
[[:<:]]
- left-hand word boundary [[:<:]]
- 左侧词边界(2[2-9]|[3-9][0-9]|[1-9][0-9]{2,})
- a group matching (2[2-9]|[3-9][0-9]|[1-9][0-9]{2,})
- 一组匹配
2[2-9]
- 2
followed with a digit from 2
to 9
2[2-9]
- 2
后跟一个从2
到9
的数字|
- or - 或者[3-9][0-9]
- a digit from 3
to 9
and then any 1 digit [3-9][0-9]
- 一个从3
到9
的数字,然后是任何 1 位数字|
- or - 或者[1-9][0-9]{2,}
- a digit from 1
to 9
and then two or more digits [1-9][0-9]{2,}
- 从1
到9
的数字,然后是两个或更多数字([.][0-9]+)?
- an optional .
- 一个可选的.
and 1+ digits和 1+ 位数字% to Fire Resistance
- a substring % to Fire Resistance
- 一个子字符串[[:>:]]
- right-hand word boundary [[:>:]]
- 右侧词边界
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.