What are the different wildcard characters that can be used with MySQL RLIKE operator?



The use of wildcards with RLIKE operators can save a lot of effort when we write a query that looks for some pattern (regular expression) in character string. The wildcards used with RLIKE are:

  • ^ − It signifies BEGINING of the string. In other words when we use this wildcard with RLIKE operator then it will find the pattern that begins with the particular string written after ^ wildcard

Example

 mysql> Select Id, Name from Student WHERE Name RLIKE '^H';  +------+---------+  | id   | Name    |  +------+---------+  | 15   | Harshit |  +------+---------+  1 row in set (0.00 sec)
  •  $ − It signifies END of the string. In other words when we use this wildcard with RLIKE operator then it will find the pattern that ends with the particular string written after $ wildcard.

Example

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) 
  •  | −It means OR. In other words when we use this wildcard with RLIKE operator then it will find the string which will have either substring written with | wildcard.

Example

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)
Updated on: 2020-06-20T11:03:30+05:30

612 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements