[英]How to match specific string pattern using REGEXP (or similar) in MySQL
I'm using the below UPDATE statement to update a flag that confirms if a Code is correctly formatted, note the code can be anywhere in 'RefCode'. 我正在使用下面的UPDATE语句来更新用于确认代码格式正确的标志,请注意该代码可以在“ RefCode”中的任何位置。 This works in Excel, but I understand MySQL REGEX is a little different to standard REGEX: 这在Excel中有效,但我了解MySQL REGEX与标准REGEX略有不同:
UPDATE tblRequests
SET flagIsRefCodeOK= (RefCode REGEXP '^[A-Z0-9]{8}-(?:[A-Z0-9]{4}-){3}[A-Z0-9]{12}$')
WHERE DataSetID=11;
In a nut shell, it should be true/[1] if the field contains ddda999d-99de-999e-999e-9b9bf9999999
: 在坚果壳中,如果该字段包含ddda999d-99de-999e-999e-9b9bf9999999
,则它应该为true / [1]:
8 alphanumeric characters
A SINGLE DASH
4 alphanumeric characters
A SINGLE DASH
4 alphanumeric characters
A SINGLE DASH
4 alphanumeric characters
A SINGLE DASH
12 alphanumeric characters
Would appreciate any assistance with this. 希望对此有所帮助。
Thnx 日Thnx
In MySQL you cannot use (?: non-capture groups )
在MySQL中,您不能使用(?: non-capture groups )
Do something like this: 做这样的事情:
UPDATE mytable
SET flag = `1`
WHERE mycolumn REGEXP "^[[:alnum:]]{8}-([[:alnum:]]{4}-){3}[[:alnum:]]{12}$"
Note that the POSIX class [:alnum:]
matches ASCII letters az, AZ and digits 0-9 请注意,POSIX类[:alnum:]
匹配ASCII字母az,AZ和数字0-9
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.