0

I won't found data from table who start following by CR and one space and 4 to 6 number

Query

SELECT `order_det_ref_no` FROM `manufacturers_order` WHERE
`order_det_ref_no` REGEXP '%^CR\s+\b\w{4,6}$%'

enter image description here

1 Answer 1

1

MySQL regex does not use regex delimiters, nor does it support \b (it uses [[:<:]] for a word start position and [[:>:]] for a word end), \s, \w regex shorthand classes. Use

REGEXP '^CR[[:space:]]+[[:alnum:]_]{4,6}$'

Note that [[:space:]] matches both horizontal and vertical whitespace, you may use [[:blank:]] if you also need to only match horizontal whitespace.

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

4 Comments

Thank you, sir, its working can you give me more detail about REGEXP in mysql query
Yes, see Syntax of MySQL Regular Expressions. The point is that it only supports a sort of POSIX regex flavor that is extremely limited in available features, but is really fast.
Sstr have random value like $str="CR | CM | EL | AD"; how can i add php varibale in regexp REGEXP '^**$str**[[:space:]]+[[:alnum:]_]{4,6}$'
Usually, in PHP, you may concatenate strings with . operator. Grouping in MySQL regex can be done with (....). Also, make sure there are no spaces around |, they will prevent matches. It should look like '^(' . str_replace(' | ', '|', $str) . ')[[:space:]]+[[:alnum:]_]{4,6}$'

Your Answer

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