![]() |
||
|
Back to basics |
||
|
Gadgets
|
Regular expression dexterity is the single most important skill
needed to be successful with code. Think of the way a card shark can
manipulate a deck of cards. That's how you need to treat regexes if you
ever expect to program your way out of a jam. That said, let's learn a few useful regular expressions, try a few tricks for building, debugging and testing regexes, and look at a couple of regex libraries. All the samples that follow use Perl, as it's the most popular language for performing regular expressions. But they can easily be adapted to other languages. The principle of regular expressions is relatively simple: The code looks for a pattern -- which could include wild card characters, exclusionary characters, repeating characters, etc. -- and either tells you it's made a match, or it performs a substitution. The likliest places to find built-in regular expression support are Perl, Tcl, Python, sed and awk (that I know of). But quite good regex libraries exist to plug into Java, C and C++. It's not my purpose here to teach you regular expressions if you don't already know them. If that's what you're looking for, I like Jon Orwant's "Perl 5 Interactive Course" for a nice introduction to regexes. For you more advanced regexers, try Jeffrey E.F. Friedl's "Mastering Regular Expressions." (More on the books here.) For starters, let's build a set of regexes to verify the code a user might enter into a Web form. Next >>
|
|
|
Home | Gadgets | Code | Links | Reads | Contact Copyright © 1999, 2001, 2002 by John H. Byrd All rights reserved. |