I\'m using regex to find specific search but the last separator getting ignore.
Must search for |49213[A-Z]| but searches for |49213[A-Z]
SELECT * FROM t
Aha. That is rather subtle.
\
escapes certain characters that have special meaning.|
("or") or .
("any byte"), etc.\|
is the same as |
.https://dev.mysql.com/doc/refman/5.7/en/regexp.html says
To use a literal instance of a special character in a regular expression, precede it by two backslash () characters. The MySQL parser interprets one of the backslashes, and the regular expression library interprets the other. For example, to match the string 1+2 that contains the special + character, only the last of the following regular expressions is the correct one:
The best fix seems to be [|]
or \\|
instead of \|
when you want the pipe character.
Someday, the REGEXP
parser in MySQL will be upgraded to PCRE
as in MariaDB. Then a lot more features will come, and this 'bug' may go away.
Why are you using |
in the pattern? Why the +
?
SELECT * FROM table WHERE (data REGEXP '\|49213[A-Z]\|')
If you want multiple:
SELECT * FROM table WHERE (data REGEXP '\|49213[A-Z]+\|')
or:
SELECT * FROM table WHERE (data REGEXP '[|]49213[A-Z][|]')