cgs – 4854 summer 2012

14
CGS – 4854 Summer 2012 Web Site Con struction and Management Instructor: Francisco R. Ortega Chapter 5 Regular Expressions

Upload: usoa

Post on 23-Feb-2016

34 views

Category:

Documents


0 download

DESCRIPTION

CGS – 4854 Summer 2012 . Instructor: Francisco R. Ortega Chapter 5 Regular Expressions. Web Site Construction and Management. Today’s Lecture. Chapter 5 Regular Expressions Talk about tutorial 4 and homework 4 Help with homework #4. Mid-Term. Mid-Term June 21 st . - PowerPoint PPT Presentation

TRANSCRIPT

PowerPoint Presentation

CGS 4854 Summer 2012 Web Site Construction and ManagementInstructor: Francisco R. Ortega Chapter 5 Regular Expressions

1Todays LectureChapter 5 Regular ExpressionsTalk about tutorial 4 and homework 4Help with homework #42Mid-TermMid-Term June 21st. Chapters 1,2,3 and 4. Possible review for mid-term June 14 (after quiz 4) or June 19Extra Credit for Mid-Term Extra credit question may be Java related or Regular Expressions (if covered before the exam)You are allowed to bring one letter size paper to the exam3ASCII Table (Part 1)

4Regular ExpressionsMatch strings of text (wiki) Sequence of regular expressions is known as a patternRegular expressions containWildcardsSpecial characters Escape sequences

5Regular Expressions 101Characters match themselves except: [\^$.|?*+()\ suppresses the meaning of special characters[] starts a character class. We match one from the class.- specifies a range of characters^ negates a character class. matches any single character except line break| matches either the left, or the right (or)6Character Classes[xyz] : will match x or y or z[a-z] : will match lowercase letters[a-zA-Z] : will match all letters[a-Z] :will not match any letters (why?) [A-z] : will match all letters but additional symbols. Why?[^abc] : Any character except for a,b or c.

7Predefined classesCharacter classMeaning.Any character except line termination\dA digit: [0-9]\DA non digit [^0-9]\sA whitespace character\SA non-whitespace character\wA word character [a-zA-Z_0-9]\WA non word character8Escape Sequence\. : would match a period[.] : would match a period\ does not lose special meaning inside square brackets [\d]9Alternationyes|noyes|no|maybeIt will match either yes,no or maybae. But only one of them. 10Grouping and Capturing(pattern)Capturing pattern.Can retrieve values from \1 thru \9ExampleText: abyes3[a-z] ([a-z]) (yes|no) \d \1 is equal to b\2 is equal to yes(?:pattern)Only used for grouping 11Ignoring case(?i)yes|no[yY] [eE] [sS] | [Nn] [Oo]12RepetitionRepetition SymbolMeaning*Matches zero or more occurrences of the preceding pattern?Matches zero or one occurrences of the preceding pattern+Matches one or more occurrences of the preceding pattern{m,n}Range of times that the pattern can repeat. ? Same as {0,1}{m}Range of exactly how many times that will match the pattern.{m,}Range of at least times that will match the pattern. + same as {1,}13Regex in javaYou will need to use two backslashes Regex: \dJava regex: \\d

1446176.0