MySQL Pattern Matching

Regex… I hate regex. But there’s nothing I can do because it is most pretty useful for pattern matching. Like, say, getting all strings that start with a certain letter range like a to c. The way to achieve this is to use the MySQL keyword REGEXP or RLIKE. Take this example to match all string that starts with this letter range a to c.

REGEXP '^[a-c]'

The ^ is used to match all strings that match within the letter range, in this example a, b and c. You can also add more letter options like

REGEXP '^[a-c, h]'

which includes strings that match h as its starting character.

It aint easy at first. You’d need to read the MySQL documents to get yourself familiarized with the necessary characters that you would need to use in order to get the match that you want.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *