Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

Learning regexes

by crenz (Priest)
on Apr 02, 2003 at 20:29 UTC ( #247591=perlquestion: print w/replies, xml ) Need Help??
crenz has asked for the wisdom of the Perl Monks concerning the following question:

A colleague of mine wants to learn about regexes. I can teach him the basics no problem, but I think such an introduction should include more than just the syntax. Issues I deem important include

So before I go and reinvent the wheel poorly, is there a good introduction to regexes available that covers usage aspects as well?

Replies are listed 'Best First'.
Re: Learning regexes
by gmax (Abbot) on Apr 02, 2003 at 21:26 UTC
Re: Learning regexes
by perlguy (Deacon) on Apr 02, 2003 at 21:29 UTC
      Yeah, I've read it. In the last chapters there's a kind of statistical/mathematical approach
      in order to explain the possibilities of various matchings. Very hard&cool!

      IMHO: perldoc perlre && perldoc perlretut
•Re: Learning regexes
by merlyn (Sage) on Apr 02, 2003 at 21:26 UTC
Re: Learning regexes
by phydeauxarff (Priest) on Apr 02, 2003 at 21:10 UTC
Re: Learning regexes
by bart (Canon) on Apr 03, 2003 at 02:04 UTC
    There's a chapter in Joseph N. Hall's book Effective Perl Programming dedicated to what you're summing up, here. That chapter, chapter 4, is freely available online as a PDF.
Re: Learning regexes
by hiseldl (Priest) on Apr 03, 2003 at 02:28 UTC

    regexEvaluater may be of interest if you would like to take a more interactive approach.

    It has menu options to insert special characters, character classes, posix character classes, quantifiers and groups. There are menu options to add regex options e.g. add 'giosm' to the end of a function. You can load a text file and run the regex on it, and it will hilight the matches, there is also an option to save the transformed text. There's also an option to save the regex as a script.

    You will need Perl 5.6 and Perl/Tk. It's a nice tool, check it out.

    What time is it? It's Camel Time!

Re: Learning regexes
by crenz (Priest) on Apr 03, 2003 at 14:30 UTC

    Thanks for the good comments. My colleague was positively surprised with the number and quality of comments!

    I think I will use the following approach:

    • Read the articles mentioned (the PDF from Effective Perl Programming sure looks good!)
    • Teach him the basics (., +, *, (/), character classes and the like) and what to use regexes for
    • Use the regex evaluator together to gain proficiency
    • Talk about basic pitfalls

    Then, after a while we'll talk again about the traps he fell into :). By that time, I will also be able to see whether the more advanced concepts (look-ahead etc.) are really necessary for the work he needs to do.

Re: Learning regexes
by SysApe9000 (Acolyte) on Apr 03, 2003 at 18:49 UTC
    As mentioned earlier, Mastering Regular Expressions is good if you want to improve your regex kung-fu. However, I would like to note that split uses regexes. The first option to split() is a regex...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://247591]
Approved by pfaut
Front-paged by VSarkiss
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2017-03-24 12:59 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (301 votes). Check out past polls.