简体   繁体   中英

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.

What is wrong with the RegEx?

MySQL doesn't support the \\d regex capture group. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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