簡體   English   中英

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

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

我有一個數據庫表,其中包含帶和不帶數字的內容。 我需要找到帶數字的條目。

例:

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.

每個條目只能包含上述數字中的一種。

我嘗試沒有成功:

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

要么

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

但它總是返回0個條目。

RegEx有什么問題?

MySQL不支持\\d regex捕獲組。 您必須使用以下之一替換:

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

所以你的查詢看起來像這樣:

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}'

關於dbfiddle.uk的演示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM