简体   繁体   English

如何使用包含千位分隔符的MySQL-Regex查询字段?

[英]How to query fields with MySQL-Regex that contain thousand separator?

I have a database table that contains content with and without numbers. 我有一个数据库表,其中包含带和不带数字的内容。 I need to find those entries with numbers. 我需要找到带数字的条目。

Example: 例:

We are going to examine 1.523 data points that were collected with 2.456.213 participants. 
Having an income of more than 1.000,20 Euros.

Each entry containg only one type of the numbers above should be found. 每个条目只能包含上述数字中的一种。

I tried without success: 我尝试没有成功:

SELECT * FROM `db_content` 
WHERE content REGEXP "\d{1,3}\\.\d{3}"

or 要么

SELECT * FROM `db_content` 
WHERE content REGEXP "\d{1,3}(.\d{3})*(\.\d+)"

but it always returns 0 entries. 但它总是返回0个条目。

What is wrong with the RegEx? RegEx有什么问题?

MySQL doesn't support the \\d regex capture group. MySQL不支持\\d regex捕获组。 You have to replace with one of the following: 您必须使用以下之一替换:

  • [0-9]
  • [[:digit:]]

So your query can look like these: 所以你的查询看起来像这样:

SELECT * 
FROM `db_content` 
WHERE content REGEXP '[0-9]{1,3}\\.[0-9]{3}'

-- or 

SELECT * 
FROM `db_content` 
WHERE content REGEXP '[[:digit:]]{1,3}\\.[[:digit:]]{3}'

demo on dbfiddle.uk 关于dbfiddle.uk的演示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM