Lecture 8 - 3/20/11 ECE 364: Software Tools Laboratory...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
3/20/11 1 ECE 364: Software Tools Laboratory Lecture 8 March 21, 2011 Lecturer: Michael Goldfarb 1 Regular Expressions § A regular expression is a pattern of characters that a text string can be matched against when performing searches § The name comes from the mathematical theory on which they are based § You will cover this in ECE270 and ECE369 2
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3/20/11 2 Basic Patterns § In its simplest form, a regular expression may be composed entirely of literals: Hello Bob 765-496-4934 § It is relatively clear what these patterns match 3 How Regular Expressions Work § It is useful to note that most regular expression matching algorithms are implemented in a similar manner to a state machine § The regex engine begins with the leftmost character in a string, checking to see if it matches the regular expression. § Only if it does not will the engine move to the next character. § This is called non-greedy matching 4
Background image of page 2
3/20/11 3 Metacharacters § A metacharacter is a character with has special meaning . Match any character except a newline ^ Match the start of the string $ Match the end of the string \ Denotes an escape sequence | Matches the left or right regex ( ) Denotes a group and matches the regex 5 Metacharacters - Quantifiers § Quantifiers allow you to specify repetition of a pattern. They are greedy by default: * Match 0 or more repetitions of preceding regex + Match 1 or more repetitions of preceding regex ? Match 0 or 1 repetitions of preceding regex {m} Match exactly m copies of preceding regex {m,} Match at least m copies of preceding regex {,n} Match at most n copies of preceding regex {m,n} Match from m to n repetitions of preceding regex 6
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3/20/11 4 Character Classes (Ranges) § Used to indicate a set of characters. Characters may be listed individually, or specified as a range separated by " - ". [A-Z] Match one character A through Z [a-zA-Z0-9$@] Match an alphanumeric, $, or @ [a-z A-Z 0-9] Match an alphanumeric or space § Metacharacters are not active inside of character classes § You can complement a character class by including "^" as the first character of the set. [^A-Z]
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/26/2011 for the course ECE 364 taught by Professor Niklaselmqvist during the Fall '10 term at Purdue University-West Lafayette.

Page1 / 11

Lecture 8 - 3/20/11 ECE 364: Software Tools Laboratory...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online