2

I am using a regulear expression im mysql like this

select * from table1 where
table1.name
REGEXP '[[:<:]]1.1[[:>:]]'

The query shows results, whose name field has value 1.1.1 also. Like this

pk  name
5   1.1
6   1.1.1

but I need to match only 1.1

Any ideas?

0

1 Answer 1

2
select * from table1 where
table1.name
REGEXP '^1.1$'

makes sure that only 1.1 is allowed (but also 1X1 or 111 because the dot matches any character - if you want to match a literal dot, use ^1\.1$).

Of course, now there's the question why you'd want to use a regex at all since it's just a literal string you're matching, not a variable pattern.

Your regex failed because you were using start-/end-of-word anchors that match between alphanumeric characters and non-alphanumerics (or start/end of string), and since [[:>:]] matches between 1 and ., the regex matched 1.1.1 at least partially.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.