Abeer zaroor Abeer zaroor - 7 months ago 15
SQL Question

white space Regex in mysql

according to mysql regex we can use

[[:space:]]*
instead of
\s*

so I have this query

select * from onet.tools_and_technology where t2_example Rlike '[[:space:]]*C++[[:space:]]*';


but it gives me this error


Error Code: 1139. Got error 'repetition-operator operand invalid' from
regexp


what I'm missing here??!!

Answer

The + character is similar to the * character in a regex: they're meta characters.

You need to escape each character with \. Because you are working in a string, you will need to escape the escape: '[[:space:]]*C\\+\\+[[:space:]]*'


Your problem can be solved without regexes, though: LIKE '% c++ %'

This is much more readable.