Pathi
Pathi

Reputation: 133

Like Function to RegexP

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?

Upvotes: 2

Views: 74

Answers (2)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626738

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.

Upvotes: 1

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

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

SELECT * FROM testtabel WHERE call_id REGEXP '(7534567|7134576)$'  ;

Upvotes: 0

Related Questions