CC SQL 9. searching using regular expression

Card Set Information

Author:
dau108
ID:
146242
Filename:
CC SQL 9. searching using regular expression
Updated:
2012-04-07 14:30:00
Tags:
CC SQL searching using regular expression
Folders:

Description:
CC SQL 9. searching using regular expression
Show Answers:

Home > Flashcards > Print Preview

The flashcards below were created by user dau108 on FreezingBlue Flashcards. What would you like to do?


  1. basic character matching
    • SELECT prod_name
    • FROM products
    • WHERE prod_name REGEXP '1000'
    • ORDER BY prod_name;
  2. performing OR matches
    • SELECT prod_name
    • FROM products
    • WHERE prod_name REGEXP '1000|2000'
    • ORDER BY prod_name;
  3. matching one or several characters
    • SELECT prod_name
    • FROM products
    • WHERE prod_name REGEXP '[123] Ton'
    • ORDER BY prod_name;
  4. matching ranges
    • SELECT prod_name
    • FROM products
    • WHERE prod_name REGEXP '[1-5] Ton'
    • ORDER BY prod_name;
  5. matching special character
    The regular expression language is made up of special characters that have specific meanings. You've already seen ., [], |, and -, and there are others, too. Which begs the question, if you needed to match those characters, how would you do so? For example, if you wanted to find values that contain the .character, how would you search for it? Look at this example:

    • SELECT vend_name
    • FROM vendors
    • WHERE vend_name REGEXP '\\.'
    • ORDER BY vend_name;
  6. matching character classes
    • Table 9.2. Character ClassesClassDescription
    • [:alnum:] Any letter or digit, (same as [a-zA-Z0-9])[:alpha:] Any letter (same as [a-zA-Z])
    • [:blank:] Space or tab (same as [\\t ])
    • [:cntrl:] ASCII control characters (ASCII 0tHRough 31 and 127)
    • [:digit:] Any digit (same as [0-9])
    • [:graph:] Same as [:print:] but excludes space
    • [:lower:] Any lowercase letter (same as [a-z])
    • [:print:] Any printable character
    • [:punct:] Any character that is neither in [:alnum:] nor [:cntrl:]
    • [:space:] Any whitespace character including the space (same as [\\f\\n\\r\\t\\v ])
    • [:upper:] Any uppercase letter (same as [A-Z])
    • [:xdigit:] Any hexadecimal digit (same as [a-fA-F0-9])
  7. matching multiple instances
    • Metacharacter Description
    • * 0 or more matches
    • + 1 or more matches (equivalent to {1,})
    • ? 0 or 1 match (equivalent to {0,1})
    • {n} Specific number of matches
    • {n,} No less than a specified number of matches
    • {n,m} Range of matches (m not to exceed 255)

    • ELECT prod_name
    • FROM products
    • WHERE prod_name REGEXP '\\([0-9] sticks?\\)'
    • ORDER BY prod_name;
  8. anchor
    • Metacharacter Description
    • ^ Start of text
    • $ End of text
    • [[:<:]] Start of word
    • [[:>:]] End of word

    • SELECT prod_name
    • FROM products
    • WHERE prod_name REGEXP '^[0-9\\.]'
    • ORDER BY prod_name;
  9. matching REGEXP behave like
    Making REGEXP Behave Like LIKE Earlier in this chapter I mentioned that LIKE and REGEXP behaved differently in that LIKEmatched an entire string and REGEXP matched substrings, too. Using anchors, REGEXP can be made to behave just like LIKE by simply starting each expression with ^ and ending it with $.

What would you like to do?

Home > Flashcards > Print Preview