1 / 39

Regular Expressions

Regular Expressions. Danny Bryant City of Atlanta. 101. About the Presenter. Danny Bryant IT Manager, Sr.- City of Atlanta. User Groups: ODTUG | OAUG | IOUG Publications & Media ODTUG (blog) –

koen
Télécharger la présentation

Regular Expressions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Regular Expressions Danny Bryant City of Atlanta 101

  2. About the Presenter Danny Bryant IT Manager, Sr.- City of Atlanta User Groups: ODTUG | OAUG | IOUG Publications & Media ODTUG (blog) – How’d You First Get Involved with ODTUG? RMOUG – SQL>SELECT Regular Expressions: A Love/Hate Relationship OraclePodcast SQL Dev 4.0 in Action at the City of Atlanta @dbcapoeira dbryant@atlantaga.gov http://www.dbaOnTap.com Danny Bryant

  3. Agenda • Simple Pattern Matching • What are Regular Expressions • META Characters • Examples • Regular Expression Function • Examples

  4. Simple Pattern Matching LIKE Operator %(multiple characters) _ (single character)

  5. Simple Pattern Matching LIKE Operator with ‘%” SELECT first_name, last_name FROM employees WHERE last_nameLIKE‘Ba%'

  6. Simple Pattern Matching LIKE Operator with ‘_’ SELECT first_name, last_name FROM employees WHERE last_nameLIKE‘Ba_da’

  7. Simple Pattern Matching What if you needed to find all words where every second character is a vowel? Regular Expressions

  8. What are Regular Expressions? • Methods of describing both simple and complex patterns for searching and manipulating • Uses META Characters for pattern matching • Oracle’s implementation is an extension of the POSIX (Portable Operating System for UNIX)

  9. META Characters

  10. META Characters

  11. META Characters Examples

  12. ^ Beginning of a line

  13. $ End of a line

  14. (string1|string2)logical OR

  15. .(dot) Single character match

  16. . Breakdown (re.d)

  17. {m} Matches exactly mtimes

  18. {m} Breakdown (s{2})

  19. *(star) Matches zero or more

  20. * Breakdown (ab*c)

  21. Regular Expression Functions • Set of SQL functions used to search and manipulate strings using Regular Expressions • These functions can be used on any data type that holds character data (CHAR, VARCHAR, CLOB, etc) • The Regular Expression must be enclosed in single quote marks

  22. Regular Expression Functions

  23. REGEXP_LIKE Similar to the LIKE operator but allows for the use of regular expressions in matching

  24. REGEXP_LIKE All employees first name of Steven or Stephen

  25. REGEXP_LIKE All employees first name of Steven or Stephen

  26. REGEXP_REPLACE Search and replace text using regular expression pattern

  27. REGEXP_REPLACE Reformat phone number from ###.###.#### to 1 (###)-###-####

  28. REGEXP_REPLACE

  29. REGEXP_REPLACE

  30. REGEXP_INSTR Searches for a string using regular expression pattern and returns the position when match is found

  31. REGEXP_INSTR Search for addresses that don’t start with a number and list the position of the first non-alpha character

  32. REGEXP_INSTR Search for addresses that don’t start with a number and list the position of the first non-alpha character

  33. REGEXP_SUBSTR Searches for a string using regular expression pattern and returns the matched substring

  34. REGEXP_SUBSTR Only return POSITION department name

  35. REGEXP_SUBSTR Only return POSITION department name

  36. REGEXP_COUNT Returns the number of times a pattern appears in the string. • Scenario 1: DNA sequence of a mouse. Need to find the number of times the sequence of Cytosine, Adenine, Thymine (cat) proteins occur. • Scenario 2: All rows where there is an ‘i’ in the first name

  37. REGEXP_COUNT Scenario 1

  38. REGEXP_COUNT Scenario 2

  39. Q/A

More Related