Regular Expressions Theory and Practice - PowerPoint PPT Presentation

About This Presentation
Title:

Regular Expressions Theory and Practice

Description:

Regular Expressions Theory and Practice – PowerPoint PPT presentation

Number of Views:67
Avg rating:3.0/5.0
Slides: 17
Provided by: jeffreyasc
Category:

less

Transcript and Presenter's Notes

Title: Regular Expressions Theory and Practice


1
Regular ExpressionsTheory and Practice
  • Jeff Schoolcraft
  • MDCFUG 12/13/2005

2
Who am I?
  • Jeff Schoolcraft
  • Senior Architect / Operations Manager at RGII
    Technologies.
  • Speaker at Usergroups
  • President WinProTeam Vienna Usergroup (.NET)
  • TDD Evangelist
  • Tool guy

3
What can you expect?
  • The gist in 60 seconds or less.
  • Theory
  • Practical Usage
  • Best Practices
  • Hands On
  • A sermon
  • Q A

4
The Gist
  • Regular Expressions (regex) describe patterns in
    strings and are often used for data validation,
    searching and text transformations.

5
Theory
  • BasicsA regular expression, often called a
    pattern, is an expression that describes a set of
    strings without actually listing its elements.
  • Say what?
  • The set of strings dog, bog, fog can be
    described by this regular expression (regex)
  • bdfog

6
Formal Language Theory
  • A Regular Language is any language where all
    possible strings of that language can be
    described by a regular expression

7
Formal Language Theory (contd)
  • Regular expressions consist of constants and
    operators that denote sets of strings and
    operations over these sets, respectively. Given a
    finite alphabet S the following constants are
    defined
  • (empty set) Ø denoting the set Ø
  • (empty string) e denoting the set e
  • (literal character) a in S denoting the set a
  • and the following operations
  • (concatenation) RS denoting the set aß a in R
    and ß in S . For example "ab", "c""d", "ef"
    "abd", "abef", "cd", "cef".
  • (alternation) RS denoting the set union of R and
    S.
  • (Kleene star) R denoting the smallest superset
    of R that contains e and is closed under string
    concatenation. This is the set of all strings
    that can be made by concatenating zero or more
    strings in R. For example, "ab", "c" e,
    "ab", "c", "abab", "abc", "cab", "cc", "ababab",
    ... .
  • http//en.wikipedia.org/wiki/Regular_expression

8
DEMO
  • All binary numbers
  • All binary numbers that start and end in 1
  • All binary number that have 00 any other bits
    followed by 111 and any other bits.

9
Practical Usage
  • In order of popularity
  • Searching
  • Much nicer than or
  • String Manipulation
  • Parsing
  • Replacement
  • Validation
  • Input validation
  • Database check constraints

10
Best Practices
  • The most important thing to remember
  • Regular Expressions are greedy
  • Make the most explicit match possible
  • Just because some implementations allow ? Dont
    fall back on that.

11
Hands On
12
A Sermon
  • Some people develop a religious fascination with
    new tools technologies (design patterns, regex,
    whatever).
  • Use the tools that make the most sense for your
    problem/solution.

13
Email Validation with REGEX?
  • Are you kidding me?
  • See email.regex
  • Multi-tiered approach, regex to test format, some
    code to test validity of email address.

14
Questions?
15
Further Resources
  • Mastering Regular Expressionshttp//www.oreilly.c
    om/catalog/regex/
  • A website, 1000s on google. http//www.regular-e
    xpressions.info/
  • Mehttp//thequeue.net/blog/http//regexadvice.co
    m/blogs/jschoolcraft/jeff_at_thequeue.net

16
Tools
  • The Regulator (http//regex.osherove.com/)
  • Expresso (http//www.ultrapico.com/Expresso.htm)
Write a Comment
User Comments (0)
About PowerShow.com