| PHP/MySQL -> | Using wildcards in MySQL LIKE and RLIKE operators |
|
The use of wildcards with LIKE and
RLIKE operators can save a lot of effort
when you write query that looks for some pattern (regular expression) in
character string. The wildcards used with LIKE are: % substitute for unlimited amount of characters at the BEGINING/END of the string. _ substitute for one character Look for Customer names that starts with "A" and fouth char is also "a":
The result will be like this:
Look for Items with price ending by ".5":
The result will be like this:
The wildcards used with RLIKE operator are: ^ signifies BEGINING of the string. $ signifies END of the string. [[:<:]] substitute characters in the string BEGINING [[:>:]] substitute characters in the string END | means OR Look for Customer names that have have substring "Aida" or substring "Nass" somewhere:
The result will be like this:
Look for Item wich name starts with "Philips" and price have digit in the range of 4-5:
The result will be like this:
Regular expression for email address validation:
The result will be like this:
"[-0-9a-z_\\.]" means any digit or (a-z) character ending with dot. "\\.[a-z]{2,3}" means any (a-z) character after dot for the length between 2 or 3 characters. |