SQL statement for column value that matches both regex

69 views Asked by At

The table "article" has a cloumn named "A_Title". I want to select the A_Title that matches exactly both /[A-Za-z]+/ and /[\x{0981}-\x{09E3}]/u regex at the same time.

I tried several methods for it, but neither is working. Giving error: #1139 - Got error 'invalid character range' from regexp

SELECT A_Title FROM article WHERE A_Title REGEXP '[A-Za-z]+.*[\x{0981}-\x{09E3}]|[\x{0981}-\x{09E3}].*[A-Za-z]+'

SELECT A_Title FROM article WHERE A_Title REGEXP '[A-Za-z]+.*[\\x{0981}-\\x{09E3}]|[\\x{0981}-\\x{09E3}].*[A-Za-z]+'

Below code works, but it is not using the same regex:

SELECT A_Title FROM article WHERE A_Title RLIKE '[A-Za-z]+.*[ঀ-৳]|[ঀ-৳].*[A-Za-z]+'
1

There are 1 answers

0
Tushar On

For MySQL regex; \x{0981} this syntax is incorrect; So, just remove the x from it in your regexp.

and then you can combine these both REGEXP statements the same way you have written your working regexp in the post :

SELECT A_Title FROM article WHERE A_Title REGEXP '[A-Za-z]+.*[\\u0981-\\u09E3]|[\\u0981-\\u09E3].*[A-Za-z]+';

As you have already tagged RLIKE in your post; you can even use it instead of REGEXP as REGEXP and RLIKE are synonyms for REGEXP_LIKE() synonym of REGEXP.