pedroooo pedroooo - 3 months ago 12
MySQL Question

Need a Regular expression for text match in mysql

Hello i need a regular expression per my sql query to match to text

"SIP/(10 NUMBERS)"


equals

"SIP/1234567890"


"SIP" are text
and 10 number randoms 0-9

UPDATE

Final text are SIP/0123456789-000001cc

where

"SIP/" is text

"0123456789" Always 10 digits

"-" is character

"000001cc" is random alphanumeric

Answer

You can use this regex:

^SIP/[[:digit:]]{10}-

Examples:

mysql> select 'SIP/0123456789-000001cc' regexp '^SIP/[[:digit:]]{10}-';
+----------------------------------------------------------+
| 'SIP/0123456789-000001cc' regexp '^SIP/[[:digit:]]{10}-' |
+----------------------------------------------------------+
|                                                        1 |
+----------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select 'SIP/123456789-000001cc' regexp '^SIP/[[:digit:]]{10}-';
+----------------------------------------------------------+
| 'SIP/123456789-000001cc' regexp '^SIP/[[:digit:]]{10}-' |
+----------------------------------------------------------+
|                                                        0 |
+----------------------------------------------------------+
1 row in set (0.00 sec)
Comments