1 / 11

Regular Expressions

Regular Expressions. What are Regular Expressions?. They are a way of specifying patterns Specifically patterns of symbols A set of rules A mini language A tiny, highly specialised programming language Number one use is for pattern matching – ie: finding things.

Download Presentation

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

  2. What are Regular Expressions? • They are a way of specifying patterns • Specifically patterns of symbols • A set of rules • A mini language • A tiny, highly specialised programming language • Number one use is for pattern matching – ie: finding things

  3. Where could you use this awesome skill? • Python • Perl, C, Java, VB.NET, Javascript • Yahoo Widgets • Excel, Word ….

  4. Using RegEx in Python

  5. Basic RegEx Syntax [abc] = either a, b or c (class) a|b = a or b [a-z] = anything between a and z [^5] = anything except 5 . = anything (except a new line) * = multiple instances of the same char (0->) \ The backslash is a metacharacter (ab)* Round brackets group chars together . ^ $ * + ? { [ ] \ | ( )

  6. Exercise 1 Which of the following matches regexp a(ab)*a • abababa • aaba • aabbaa • aba • aabababa

  7. Exercise 2 • Which of the following matches regexp abc|xyz • abc • xyz • abc|xyz

  8. Repetitions • a* = zero or more repetitions of a • a+ = one or more repetitions of a • a? = zero or one repetitions of a • (in other words, might not be there)

  9. Exercise 3 • Which of the following matches regexp ab+c? • abc • ac • abbb • bbc

  10. Exercise 4 • Which of the following matches regexp a.[bc]+ • abc • abbbbbbbb • azc • abcbcbcbc • ac • asccbbbbcbcccc

More Related