MySQL has another type of pattern matching known as extended regular expressions. It performs a pattern match of a string expression against a pattern. If the pattern finds a match in the expression, it returns 1, else it returns 0.
When you test for a match pattern, use the REGEXP and NOT REGEXP operators.
Metacharacter | Descriptions |
---|---|
^ | Matches the position at the beginning of the searched string |
$ | Matches the position at the end of the searched string |
. | Matches any single character |
[…] | Matches any character specified inside the square brackets |
[^…] | Matches any character not specified inside the square brackets |
p1|p2 | Matches any of the patterns p1 or p2 |
* | Matches the preceding character zero or more times |
+ | Matches preceding character one or more times |
{n} | Matches n number of instances of the preceding character |
{m,n} | Matches from m to n number of instances of the preceding character |
To performs a match pattern of a string expression against a pattern, use the following syntax:
Parameters:
tablename: The table name from which you want to fetch the records.
REGEXP: To performs a match pattern of a string expression against a pattern.
Note:
In the above example, we are showing how to find out "firstName" whose last name starts with character A, B or C.
You can use MySQL Command Line Client to performs a match pattern of a string expression against a pattern. It will look like this:
Note:
In the above example, we are showing how to find the "address" whose name contains "PVR", you use the above query:
You can use MySQL Command Line Client to performs a match pattern of a string expression against a pattern. It will look like this: