skip to Main Content

Basically I have below query.

Select * from testtabel
     where call_id like '%7534567' 
        or call_id like '%7134576' or ..... ;

7534567,7134576 are not any pattern. So I need to check any call_id which ends 7534567 or 7134576. since I have many to check without using LIKE can I use regexp to check that?

refered Using multiple values in mySQL regexp and
I tried as below,

Select * from testtabel  where call_id REGEXP '^(7534567|7134576)$';

But this provides zero records. Can someone show me how should I do that?

2

Answers


  1. Did you try like this to match multiple patterns using REGEXP?

    SELECT * FROM testtabel WHERE call_id REGEXP '(7534567|7134576)$'  ;
    
    Login or Signup to reply.
  2. The ^ anchor matches (here, requires the match at) the start of the string.

    You need to use

    where call_id REGEXP '([^0-9]|^)(7534567|7134576)$'
    

    Details:

    • ([^0-9]|^) – any non-digit char or start of string
    • (7534567|7134576)7534567 or 7134576 char sequence
    • $ – end of string.

    See the regex demo.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search