Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does MySQL support a number or digit wildcard pattern?

I want to select titles that have a number after a certain character. Example:

SELECT * FROM table WHERE title LIKE '%- H(any number)'

How would I select any number in this statement 1-10000000 if the number exists?

like image 618
user989990 Avatar asked Jan 18 '12 00:01

user989990


People also ask

Does MySQL support wildcard?

MySQL Wildcards A wildcard character is used to substitute one or more characters in a string. Wildcard characters are used with the LIKE operator. The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

What regex does MySQL use?

MySQL uses C escape syntax in strings (for example, \n to represent the newline character). If you want your expr or pat argument to contain a literal \ , you must double it.

What is pattern matching in MySQL?

SQL pattern matching enables you to use _ to match any single character and % to match an arbitrary number of characters (including zero characters). In MySQL, SQL patterns are case-insensitive by default.

Does MySQL support Ilike?

It is in PostgreSQL the keyword ILIKE can be used instead of LIKE to make the match case-insensitive according to the active locale. This is not in the SQL standard but is a PostgreSQL extension. In MySQL you do not have ILIKE.


2 Answers

SELECT * FROM table WHERE title REGEXP '.*- H[0-9]+'

That seems like the kind of thing you're looking for.

like image 86
Niet the Dark Absol Avatar answered Sep 27 '22 22:09

Niet the Dark Absol


SELECT * FROM table WHERE title RLIKE '- H[:digit:]{1,7}$';

will give you 1-9999999

like image 43
Eugen Rieck Avatar answered Sep 27 '22 23:09

Eugen Rieck