user2599329
user2599329

Reputation:

REGEX in mysql query

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

Upvotes: 0

Views: 50

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627607

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.

Upvotes: 1

Related Questions