Using the wildcard character of the RLIKE operator can save a lot of effort when we write queries that find a certain pattern (regular expression) in a string. The wildcard used by RLIKE is:
^- It represents the BEGINING of the string. In other words, when we use this wildcard with RLIKE operator, it will find the pattern starting with a specific string written after the ^ wildcard
mysql> Select Id, Name from Student WHERE Name RLIKE '^H'; +------+---------+ | id | Name | +------+---------+ | 15 | Harshit | +------+---------+ 1 row in set (0.00 sec)
$- It indicates the end of the string. In other words, when we use this wildcard with the RLIKE operator, it will find the pattern ending with the specific string written after the $ wildcard.
mysql> Select Id, Name from Student WHERE Name RLIKE 'v$'; +------+--------+ | Id | Name | +------+--------+ | 1 | Gaurav | | 2 | Aarav | | 20 | Gaurav | +------+--------+ 3 rows in set (0.00 sec)
|- means "or". In other words, when we use this wildcard with RLIKE operator, it will find strings that have substrings written with |. Wildcard.
mysql> Select Id, Name from Student WHERE Name RLIKE 'Gaurav|raj'; +------+---------+ | Id | Name | +------+---------+ | 1 | Gaurav | | 20 | Gaurav | | 21 | Yashraj | +------+---------+ 3 rows in set (0.00 sec)
The above is the detailed content of What different wildcard characters can be used with the MySQL RLIKE operator?. For more information, please follow other related articles on the PHP Chinese website!