You have seen MySQLi design coordinating with LIKE ...%. MySQLi upholds another sort of example coordinating activity dependent on normal articulations and the REGEXP administrator. In the event that you know about PHP or PERL, at that point it's straightforward for you to comprehend on the grounds that this coordinating is very much like those scripting normal articulations.
Following is the table of example, which can be utilized alongside REGEXP administrator.
Pattern | What the pattern matches |
---|---|
^ | Beginning of string |
$ | End of string |
. | Any single character |
[...] | Any character listed between the square brackets |
[^...] | Any character not listed between the square brackets |
p1|p2|p3 | Alternation; matches any of the patterns p1, p2, or p3 |
* | Zero or more instances of preceding element |
+ | One or more instances of preceding element |
{n} | n instances of preceding element |
{m,n} | m through n instances of preceding element |
Examples
Presently dependent on above table, you can gadget different kind of SQL inquiries to meet your prerequisites. Here, I'm posting not many for your arrangement. Consider we have a table called tutorials_inf and it's having a field called name −
Question to locate all the names beginning with 'sa'
mysql> SELECT * FROM tutorials_inf WHERE name REGEXP '^sa';
The example yield ought to be this way −
+----+------+
| id | name |
+----+------+
| 1 | sai |
+----+------+
1 row in set (0.00 sec)
Inquiry to locate all the names finishing with 'ai'
mysql> SELECT * FROM tutorials_inf WHERE name REGEXP 'ai$';
The example yield ought to be this way −
+----+------+
| id | name |
+----+------+
| 1 | sai |
+----+------+
1 row in set (0.00 sec)
Inquiry to locate all the names, which contain 'a'
mysql> SELECT * FROM tutorials_inf WHERE name REGEXP 'a';
The example yield ought to be this way −
+----+-------+
| id | name |
+----+-------+
| 1 | sai |
| 3 | ram |
| 4 | johar |
+----+-------+
3 rows in set (0.00 sec)
Inquiry to locate all the names beginning with a vowel
mysql> SELECT * FROM tutorials_inf WHERE name REGEXP '^[aeiou]';