Download
regular expressions n.
Skip this Video
Loading SlideShow in 5 Seconds..
Regular Expressions PowerPoint Presentation
Download Presentation
Regular Expressions

Regular Expressions

69 Views Download Presentation
Download Presentation

Regular Expressions

- - - - - - - - - - - - - - - - - - - - - - - - - - - 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