Wildcards are, as in other languages, heavily used in MySQL. Besides being used in regular expressions, they are frequently used in query statements as well, such as SELECT * or LIKE '%'.
Here is the list of common wildcard symbols in MySQL:
SYMBOL | EXAMPLE | DESCRIPTION |
---|---|---|
* | SELECT * FROM | Used as 'find all' or 'select all'. The most common wildcard in MySQL |
% | LIKE '%' | Represents a match of any string with 0 or more characters |
_ | LIKE '_' | Represents a match of any single character |
^ | REGEXP '^abc' | Matches the beginning of the string |
$ | REGEXP 'abc$' | Matches the end of the string |
. | REGEXP 'abc.' | Matches any character of the string |
[...] | REGEXP '[a-c]' | Matches any character listed between the brackets |
[^...] | REGEXP '^[afgn]' | Matches any string that does not contain those characters within the bracket |
abc|bc|ced | REGEXP 'name|letter|address' | Matches any of the characters given in the pattern |
* | REGEXP '^[a].*b&' | Matches zero or more instances of that preceding pattern |
+ | REGEXP '^[abc]d+' | Matches one or more instances of that preceding pattern |
{n} | REGEXP '^[a-e]{2}' | Matches 'n' instances of the preceding pattern |
{m,n} | REGEXP '^[a-e]{2,4}' | Matches 'm' through 'n' instances of the preceding pattern |
Comments
No comments have been made yet.
Please login to leave a comment. Login now