1

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'. This works in Excel, but I understand MySQL REGEX is a little different to standard 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:

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

1 Answer 1

2

In MySQL you cannot use (?: 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 a-z, A-Z and digits 0-9

Sign up to request clarification or add additional context in comments.

3 Comments

FYI Updated to use POSIX class alnum which matches ASCII digits and letters
That's great, can we tweak so that it will pick up that pattern among other text. ie: //The Code is ddda999d-99de-999e-999e-9b9bf9999999!//
Sorry for the delay, it was night time. Yes! All we need to do is remove the start and end anchors: (the caret ^ and dollar $at the ends) ...REGEXP "[[:alnum:]]{8}-([[:alnum:]]{4}-){3}[[:alnum:]]{12}" Let me know if you need more tweaks. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.