From the course: MySQL Essential Training (2019)

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Regular expressions

Regular expressions

- [Instructor] Regular expressions are a language for searching text. The language was popularized in UNIX tools like grep, AWK, and sed, and became more widely used in Perl. Today many tools support regular expressions including MySQL. For example, if I want to find all the countries that end in Y, I can use a regular expression like this. And we'll start by using the world database, USE world. And I'll SELECT Name FROM country WHERE Name RLIKE, which is like the LIKE clause but for regular expressions, and I'll put a regular expression in quote marks here. That's a y with a dollar sign, ORDER BY Name, and when I execute this query, I get all the countries that end in the letter Y. Now, using regular expressions I can do something even more complicated if I like. For this regular expression I can say, look for an X or a Y followed by an A or an I, and when I execute I get countries that have an X or a Y, followed by an A or an I. So there's Guyana, Kenya, and Libyan, I'm not going to…

Contents