0

I'm trying the following instruction and I don't understand the TRUE value returned :

SELECT '1' ~ '(0[1-9])|[10-15]' ;

?column?
boolean
----------
t

If I make it simplier again, I still don't understand the value returned :

SELECT '1' ~ '[10-15]' ;

?column?
boolean
----------
t

Thank you for helping !

Thomas

1
  • i think you could use SELECT '1' ~ '(0[1-9])|(1[0-5])'; Commented Jul 10, 2014 at 7:27

1 Answer 1

4

This regex:

[10-15]

doesn't mean what you think it means. The things inside a character class (i.e. [...]) are individual characters, not strings. So that regex matches a '1', anything between '0' and '1', or a '5'; simplifying, we have [015]. In particular, that regex does not match anything between '10' and '15' as you seem to think.

I think you're looking for:

(0[1-9])|(1[0-5])

You just need to factor out the '1' in the second part of the alternation in the same way that you factored out the '0' in the first part.

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

1 Comment

That's it, thank you so much ! I didn't understand that... It is perfectly clear now. Have a good day.

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.