SlideServe
Menu
Préférences
© SlideServe · v2026

Understanding Regular Expressions in MySQL: Patterns and Queries

alden-gallagher avatar
13 diapositives · 262 Views · Nov 30, 2014

This guide provides an overview of how to use regular expressions (REGEXP) in MySQL. With REGEXP, you can create powerful SQL queries by defining patterns for matching strings in your database. Learn how to select customers based on various conditions using REGEXP, such as names containing specific characters or patterns. Key examples include finding names starting with specific letters, containing repeated characters, or having digits in addresses. Master these techniques to enhance your data retrieval strategies using meta-characters and pattern matching.

Understanding Regular Expressions in MySQL: Patterns and Queries - slide 1
01 / 13Understanding Regular Expressions in MySQL: Patterns and Queries
1 / 17

Télécharger la présentation

Understanding Regular Expressions in MySQL: Patterns and Queries
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. SQL Regular Expressions

  2. REGEXP • Mysql supports regular expressions • Keyword is REGEXP • Select columns from tableName where columnName regexp ‘someRegularExpression’

  3. REGEXP • Concept and syntax are somewhat similar to the regular expression concept and syntax in various programming languages (Perl, PHP, Java, ..)

  4. REGEXP • Customers having a p in their name • Select * from customer where name regexp ‘p’; • Customers containing pre in their name • Select * from customer where name regexp ‘pre’;

  5. REGEXP • Use of meta-characters enable more powerful SQL queries • [ ]  in this set • Customers who have a, b, or c in their name • Select * from customer where name regexp ‘[abc]’;

  6. REGEXP • [^ ]  not in this set • Customers who have a character that is not a to x in their name • Select * from customer where name regexp ‘[^a-x]’;

  7. REGEXP • ^  matches at beginning • $  matches at the end • .  matches any character • *  0 or more • Customers who have a name that starts with a letter between d and z and ends with e • Select * from customer where name regexp ‘^[d-z].*e$’;

  8. REGEXP • Do not confuse • ^ inside the square brackets, i.e. [^ ] not in set • With • ^  matches at the beginning

  9. REGEXP • ?  0 or 1 • +  1 or more • ab | xyz  matches ab or xyz • Customers who have a name that starts with a or c • Select * from customer where name regexp ‘^(a|c)’;

  10. REGEXP • {n}  n instances of character • {m, n}  between m and n (included) instances of character • Customers who have a name that contains 2 consecutive s • Select * from customer where name regexp ‘s{2}’;

  11. REGEXP • [a-z] or [[:alpha:]]  matches a letter • [0-9] or [[:digit:]]  matches a digit • Customers who have an address that contains a digit • Select * from customer where address regexp ‘[0-9]’;

  12. REGEXP • [[:character_class:]]  matches a character belonging to the class character_class • Character_class could be: digit, alpha, alnum, space, blank, lower, upper, .. • http://dev.mysql.com/doc/refman/5.0/en/regexp.html

  13. REGEXP • Customers from a city that has a white space character in it • Select * from customer where city regexp ‘[[:space:]]’; • Could also use: • Select * from customer where city regexp ‘ ’;