Reputation: 2664
I need a MySQL pattern to match a number, followed by a question mark. I need something like ... like '%[0-9]?%' but I have no idea how to create this regular expression.
http://dev.mysql.com/doc/refman/5.0/en/pattern-matching.html does not help.
Thanks!
Upvotes: 0
Views: 4181
Reputation: 19510
you could try this:
SELECT * FROM YourTable WHERE YourField REGEXP '[0-9]\\?'
That will return rows where YourField
contains a number followed by a ?
anywhere in the value.
If you want it to only match if the whole field is a number followed by a ?
. I.e. 9?
then you could use this regex instead:
^[0-9]\\?$
Upvotes: 4
Reputation: 43494
I guess you're looking for something like this:
select * from table
where field rlike '[0-9]\\?'
Remember to escape the question mark. Otherwise, it will make the number optional.
Upvotes: 1