Regular Expressions in ColdFusion MX7 - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Regular Expressions in ColdFusion MX7

Description:

Group patterns. Match at least x and not more ... IsValid('regex' or 'regular_expression', value, pattern) ... REReplace(string, pattern, substring [, scope ] ... – PowerPoint PPT presentation

Number of Views:85
Avg rating:3.0/5.0
Slides: 12
Provided by: traberc
Category:

less

Transcript and Presenter's Notes

Title: Regular Expressions in ColdFusion MX7


1
Regular Expressions in ColdFusion MX7
  • Seattle CFUG Meeting
  • Thursday November 3, 2006
  • Presented by Traber Campbell

2
What is a regular expression?
  • A regular expression (regex) is a string that
    describes or matches a set of strings, according
    to certain syntax rules
  • A standard definition for searching and replacing
    text strings works in CF, Java, Perl, php, UNIX
    commands such as grep and awk, and many more!
  • An incredibly powerful way to search, replace,
    and parse text

3
What can I use it for?
  • Validate user input
  • Find specific text
  • Parse a string
  • Replace verb forms
  • Add link tags to pages
  • Imagine the possibilities!

4
Where can I use a regex?
  • ltcfparamgt
  • IsValid()
  • REFind()
  • REFindNoCase()
  • REReplace()
  • REReplaceNoCase()

5
Special characters
6
CF usage
  • ltcfparam namevariable_name typeregex or
    regular_expression patternregular expressiongt
  • IsValid("regex" or "regular_expression", value,
    pattern)
  • REFind(pattern, string , start ,
    returnsubexpressions )
  • REReplace(string, pattern, substring , scope )
  • REFindNoCase() and REReplaceNoCase() are
    case-insensitive versions of REFind() and
    REReplace(). The syntax is identical

7
ltcfparamgt examples
  • Validate from a list
  • ltcfparam nameForm.Select typeregex
    pattern(redgreenblue)
  • Validate ssn
  • ltcfparam nameForm.SSN typeregex
    pattern\d3-\d2-\d4gt

8
Syntax (LiveDocs)
  • Go to LiveDocs

9
Badass CF return subexpressions
  • REFind() supports an option called
    returnsubexpressions
  • If false (the default), REFind() returns the
    position in the string where the match begins, or
    0 if not found
  • If true, REFind() returns a structure that
    contains two arrays, len and pos
  • Why is this cool? The returned arrays contain
    the start position and length of EVERY matched
    expression in the string. You can validate and
    parse data in a single expression.

10
A few words of caution
  • ColdFusion supports the basic regular expression
    syntax
  • ColdFusion regular expressions are not 100
    Perl-compatible. Some Perl examples (especially
    more complex ones) may not work in CF.

11
More Information
  • Macromedia ColdFusion LiveDocs (http//livedocs.ma
    cromedia.com/coldfusion/7/) Regex in CF,
    including syntax and examples.
  • Mastering Regular Expressions, Third Edition, by
    Jeffrey E. F. Freidl (OReilly) Everything you
    ever wanted to know about regular expression
  • Perl Cookbook, Second Edition By Tom
    Christiansen, Nathan Torkington (OReilly) Perl
    is all about regex. Lots of examples.
  • Teach Yourself Regular Expressions in 10 Minutes,
    by Ben Forta obligatory Forta reference ?
  • Wikipedia (really) (http//en.wikipedia.org/wiki/R
    egular_expression) Good intro, examples, and
    links
  • Regular Expression Library (http//regexlib.com/)
    Why reinvent the wheel?
Write a Comment
User Comments (0)
About PowerShow.com