Jimit
Jimit

Reputation: 2259

Regular expression problem

I am having problem with regular expression. I am using regex in query shown as below.

SELECT *
FROM ad
WHERE platform_specific_selection
REGEXP '[\|]{0,1}19[\|]{0,1}'

It gives me somewhat wrong result shown as below.

  1. 19|21|
  2. 0|19|20|22|
  3. 19|
  4. 0|919|

I wanted to match exact 19 using regex and I don't want 0|919| this value in result. Can anybody give me exact regex for the same?

Upvotes: 0

Views: 49

Answers (2)

Mat
Mat

Reputation: 206689

This should work:

select * from t where a REGEXP '(^|[|])19([|]|$)';

(The idea is to allow either | or start-of-string on the left, and | or end-of-string on the right.)

Upvotes: 3

gadelat
gadelat

Reputation: 1470

Why regex, LIKE is sufficient for this

SELECT *
FROM ad
WHERE platform_specific_selection
LIKE '%|19|%'

Upvotes: 0

Related Questions