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

CS 211 Regular Expressions

245 Views Download Presentation
Download Presentation

CS 211 Regular Expressions

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. CS 211Regular Expressions

  2. Today’s Lecture • Review Chapter 4 • Go over exercises

  3. Processing Input • If we know how to read in a line of input, what else might we want to do with it? • Analyze it in some way, based on some pattern • Extract certain values out of it, based on some pattern • We can create regular expressions to identify patterns, and then use them to extract the relevant info out of the pattern. • A regular expression represents a pattern • Can be used to "match"a particular string→ With Scanner’s findInLine() method • Java represents a regular expression with a String literal Regular Expressions: appendix H in the text.

  4. Special Symbols: Repetition

  5. Special Symbols: "character classes" Many more character classes can be found at:http://docs.oracle.com/javase/1.4.2/docs/api/java/util/regex/Pattern.html

  6. Special Symbols: Pre-defined groups * note: there is a space char in this. Other whitespace chars also, but their unicode representations were omitted here.

  7. Special Symbols: everything else the backslash is used to escape any special character, so that we can match the character itself. a* matches zero or more a's a\* matches an a followed by a star\b "matches" the gap between characters, instead of a particular character. \bhe\b would match within "if he is"→ wouldn't match within "if she is" or "anthem". † here, ★ could be [,],*,+,?,{,},and so on. It's a placeholder for the special symbols, and ★ would not show up in a regular expression itself.

  8. Representing Regular Expressions in Java • We use a String literal to represent a regular expression in Java. • This means that " must be escaped: \" • This also means the \ must also be escaped! \\" (represents ") • Suggested conversion: write the regExp on paper, carefully represent each character correctly inside the String, one at a time:

  9. Let’s go over the exercises

  10. Questions?