Words - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Words

Description:

Regular expressions are used to specify search strings. ... opposite of a pattern, use the caret (^) in front of the pattern, enclosed in square brackets. ... – PowerPoint PPT presentation

Number of Views:19
Avg rating:3.0/5.0
Slides: 13
Provided by: arts57
Category:
Tags: caret | words

less

Transcript and Presenter's Notes

Title: Words


1
Words
  • Words are the building blocks of sentences

2
Regular expressions (in Perl)
  • a regular expression is an algebraic notation
    for characterizing a set of strings p. 22
  • Regular expressions are used to specify search
    strings.

3
Sequences of characters
  • Matching a sequence of characters
  • //
  • Examples
  • /a/ matches the character a
  • /fred/ matches the string fred
  • Note
  • /fred/ does not match Fred!

4
Disjunction
  • Square brackets are used to indicate disjuction.
  • Examples
  • /Ff/ matches either f or F
  • /Ffred/ matches either fred or Fred

5
Ranges
  • Sometimes it is useful to specify any digit or
    any letter.
  • Any digit can be written as /0123456789/
  • An alternative is to use a special range
    notation /0-9/
  • Any letter can be specified as /A-Za-z/

6
Negation
  • To search for the opposite of a pattern, use the
    caret () in front of the pattern, enclosed in
    square brackets.
  • Examples
  • /a/ matches anything except a
  • /0-9/ matches anything except a digit
  • N.B. Every line ends with a newline (\n)!

7
Matching 0 or 1 occurrence
  • The ? matches zero or one occurrences of the
    preceding expression.
  • Examples
  • /a?/ matches a or (nothing)
  • /cats?/ matches cat or cats

8
The Kleene star and plus
  • The Kleene star () matches zero or more
    occurrences of the preceding expression.
  • Examples
  • /a/ matches , a, aa, aaa, etc.
  • /ab/ matches , a, b, aa, ab, ba,
    bb, etc.
  • matches one or more occurrences

9
Wildcard
  • The period (.) matches any single character
    except the newline (\n).

10
Anchors
  • Anchors are used to restrict a match to a
    particular position within a string.
  • anchors to the start of a line
  • anchors to the end of a line
  • \b anchors to a word boundary
  • \B anchors to a non-boundary

11
Conjunction
  • Two regular expressions are conjoined by
    juxtaposition (placing the expressions side by
    side).
  • Examples
  • /a/ matches a
  • /m/ matches m
  • /am/ matches am but not a or m alone

12
Disjunction
  • We have already seen disjunction of characters
    using the square bracket notation
  • General disjunction is expressed using the
    vertical bar (), also called the pipe symbol.
Write a Comment
User Comments (0)
About PowerShow.com