1 / 11

Why? (Wh Why)

Why? (Wh Why). Regular expressions provide a means of identifying if a string of characters is allowed in a particular language . Regular expressions are used by many text editors, e.g. to find matches to searches.

dallon
Download Presentation

Why? (Wh Why)

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. Why? (Wh Why) • Regular expressions provide a means of identifying if a string of characters is allowed in a particular language. • Regular expressions are used by many text editors, e.g. to find matches to searches. • All regular expressions can be represented using a finite state machine, and vice versa.

  2. More RegEx Characters • ^ (not in a group) – beginning of the line • $ - the end of the line so • ^ftp – ftp at the beginning of a line • end$ - end at the end of a line • ^$ - a blank line

  3. Groups • [qjk] - Either q or j or k • [^qjk] - Neither q nor j nor k • [a-z] - Anything from a to z inclusive • [^a-z] - No lower case letters • [a-zA-Z] - Any letter • [a-z]+ - Any non-zero sequence of lower case letters

  4. Special characters • \n = A newline • \t = A tab • \w = Any alphanumeric (word) character, The same as [a-zA-Z0-9_] • \W = Any non-word character, the same as [^a-zA-Z0-9_] • \d = Any digit. The same as [0-9] • \D = Any non-digit. The same as [^0-9] • \s = Any whitespace character: space, tab, newline, etc • \S = Any non-whitespace character • \b = A word boundary, outside [ ] only • \B = No word boundary

  5. Challenge 1 • Create a regular expression that will match the name, in lowercase, of each of the days of the week. • Make sure it only matches days of the week – within reason.

  6. Challenge 2 • Create a regular expression for a real number • Eg 1, -1.45, 2002.876, -17

  7. Challenge 3 • Create the smallest regular expression that will match the name (lower case) of every month that has 30 days, and matches no other months. • Do the same for 31 days.

  8. RegEx and FSAs • What is the regular expression associated with this FSA? I think! 0*1+0+1+ But don’t take my word for it

  9. Challenge 4 • Create an FSA for this Regular Expression. 1(1|0)*1*(1|0)+1

More Related