![]() ![]() The is used to match any upper case letter. SELECT * FROM `movies` WHERE `title` REGEXP ‘^’ will give all the movies containing characters other than the ones in “vwxyz”. The charlist is used to match any characters excluding the ones enclosed. SELECT * FROM `movies` WHERE `title` REGEXP ‘’ will give all the movies containing any single character in “vwxyz”. The charlist is used to match any of the enclosed characters. ![]() SELECT * FROM movies WHERE `year_released` REGEXP ‘200.’ will give all the movies released in the years starting with characters “200” followed by any single character. The dot (.) metacharacter is used to match any single character in exception of a new line. SELECT * FROM `categories` WHERE `category_name` REGEXP ‘com?’ will give all the categories containing string com. ![]() The question (?) metacharacter is used to match zero (0) or one instances of the strings preceding it. SELECT * FROM `movies` WHERE `title` REGEXP ‘mon+’ will give all movies containing characters “mon”. The plus (+) metacharacter is used to match one or more instances of strings preceding it. For Example, Da Vinci Code, Daddy’s Little Girls. SELECT * FROM movies WHERE title REGEXP ‘da*’ will give all movies containing characters “da”. The asterisk (*) metacharacter is used to match zero (0) or more instances of the strings preceding it They allow us to fine tune our pattern search results using regular expressions. Suppose we want to search for movie titles that start with the pattern “code” only using a regular expression, how would we go about it? The answer is metacharacters. Let’s now look at more advanced regular expression pattern matches. What we looked at in the above example is the simplest form of a regular expression. ‘^’ the caret (^) means that the pattern match should be applied at the beginning and the charlist means that the movie titles starting with any of the enclosed characters is excluded from the result set. ![]() Let’s now take a close look at our regular expression responsible for the above results. SELECT * FROM `movies` WHERE `title` REGEXP '^' Įxecuting the above script in MySQL workbench against the myflixdb gives us the following results. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |