Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

Training non-programmers in Perl regexps

by young_stu (Beadle)
on Jul 09, 2005 at 02:05 UTC ( #473629=perlquestion: print w/replies, xml ) Need Help??
young_stu has asked for the wisdom of the Perl Monks concerning the following question:

Hello All:

I'm working on a big data-munging project, and need to train some of our staff to write perl regular expressions in order to search for patterns in text.

These folks I'll be training have zero prior coding experience (in Perl or otherwise) and zero interest in learning to code. But they've told me they're willing to learn what I told them was "just one part" (hm...) of the Perl language so that we can get our job done faster and better.

So what I'm going to try to do is to teach them how to write regexps and nothing else. Has anyone ever tried something like this? If so, any tips? Are there any regexp tutorials out there that explain regular expressions in a way that abstracts from all other aspects of Perl?

  • Comment on Training non-programmers in Perl regexps

Replies are listed 'Best First'.
Re: Training non-programmers in Perl regexps
by Zaxo (Archbishop) on Jul 09, 2005 at 02:48 UTC

    For that kind of student, I like to introduce them in three stages, leaving out fancy stuff like extended constructs.

    1. literal matches, easy for everyone
    2. builtin character classes and escaped characters, give them a little power
    3. user character classes and anchors, separate the sheep from the goats

    The omission of alternation is intentional. Unsophisticated users overuse them and can easily land themselves in a computational tarpit.

    The postgraduate course is to point out some of the other things possible and refer to perlretut and perlre.

    The key is to show them new things that are useful to them right away. Don't demand big conceptual leaps without motivation, and allow them to practice before demanding another.

    An editor which does incremental regex searches with highlighting is valuable for illustrating how regexen work, live. Emacs incremental search is documented in info emacs Incremental Search. Vim documents its version in the "pattern.txt" manual chapter.

    After Compline,

      Speaking towards an editor that does incremental regex searching with highlighting...
      Eclipse Perl Intergration
      It is a Perl plugin for Eclipse. I have only used it for the Regexp highlighting that you speak of. When I have a complicated regexp, it is nice to be able to step through it piecemeal with this plugin and see where it works and were it doesn't.
Re: Training non-programmers in Perl regexps
by eyepopslikeamosquito (Chancellor) on Jul 09, 2005 at 02:34 UTC

    Jeffrey Friedl's Mastering Regular Expressions is a brilliant book. Though the book as a whole is too advanced for non-programmers, the first chapter "Introduction to Regular Expressions" should prove interesting reading for a keen and intelligent non-programmer, explaining in detail how regular expressions work. Not only that, but you could use some of the many excellent examples from this book to help you teach the non-programmers.

    Update: I just remembered japhy's CPAN module YAPE-Regex-Explain which might come in handy because it explains a regex in English. An example of its use can be found in Re: This looks like someone sneezed and hit the keyboard.

Re: Training non-programmers in Perl regexps
by planetscape (Chancellor) on Jul 09, 2005 at 03:30 UTC
Re: Training non-programmers in Perl regexps
by davidrw (Prior) on Jul 09, 2005 at 02:34 UTC
    I haven't tried any of them, but i believe some IDE's have regular expression builders.. googling for "activestate perl regular expression editor" led me to Visual Perl which is a complete Perl development environment plug-in for Visual Studio .NET and has a Regular Expression (Rx) toolkit for almost effortless creation and debugging of powerful regular expressions.

    Other than that, if they're are to be totally isolated from code but still help with the patterns, there's probaly a decent amount of help they can be and you can do the actual perl implementation.. some thoughts:
    • They can describe patterns in a pseudo-code manner. "Will have 2 letters followed by 6 digits and then either 'ABC' or 'XYZ'"
    • They can provide lists of example strings that should match, and lists of example strings that should not match.
    • you can start with the pseudo-code and introduce the basics from there so they can adopt things like \d, \D, \S and \s in their short-hand
    • depending on how they learn, you can give more (greediness, quantifiers, etc).. maybe let them know at least that those and other things (look ahead/behinds) are possible so they can take that into account in the pseudo-code w/o knowing the real syntax.
    • hopefully they can pick up enough from seeing how their english descriptions turn into patterns to speed along your development
Re: Training non-programmers in Perl regexps
by grantm (Parson) on Jul 09, 2005 at 02:39 UTC
    I'll punt on the tutorial angle for now, and just point you in the direction of twiddle-regex which is a Tk app that allows you to specify some input data and a regex and see where it matches. Very handy for trying things out.
Re: Training non-programmers in Perl regexps
by Ctrl-z (Friar) on Jul 09, 2005 at 09:56 UTC
    You might be interested in The Regex Coach

    time was, I could move my arms like a bird and...
Re: Training non-programmers in Perl regexps
by nothingmuch (Priest) on Jul 09, 2005 at 02:50 UTC
    Make sure they know strings well (array of chars, series of bytes in memory, can be indexed, copied, broken up, what it looks like, what ASCII is, etc).

    From then on, a regex is really just 'try this. if it doesn't work, go back and try something else'. The language for defining the values for this algorithm are very intuitive when you grok strings, and it's only the complex stuff (shameless plug: Re: Parsing a macro language.. buaahahaha) that really needs learning. For that there are good books, perlretut, perlrequick, and for deep problems, perlre.

    Good luck!

    zz zZ Z Z #!perl
Re: Training non-programmers in Perl regexps
by strat (Canon) on Jul 09, 2005 at 08:30 UTC

    Is grep (or better: egrep) a good starting point for examples? or:

    perl -ne 'print if /xyz/' file

    In my "Introduction into Perl" (available in German at my Homepage - Talks called "Einführung in Perl" -> PDF), I try to give an introduction into REs at the end, and with some additional examples (e.g. how to check a date or ip address) we try to build together most of the pupils understand it rather fast. If you want to use it (and perhaps translate it), go on

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8."

Re: Training non-programmers in Perl regexps
by tphyahoo (Vicar) on Jul 09, 2005 at 15:26 UTC
    Strongly agree with ctrl-z about the regex coach, which, he didn't mention, is free and comes with an interactive walkthrough. See also editpad, which isn't free, but comes with a trial version, and is a "real" get-work-done type tool, unlike regex coach, which is more for just learning. Great tutorial included with editpad as well, which is free. Basically the same functionality as emacs but more user friendly.... oh, and checking out the web site, I would try out regex buddy as well, which seems to be similar to regex coach but more powerful, and non-free. As you can see in the screenshot, it tkaes a regex and breaks it down into the component parts, explaining each of the parts in english. Looks perfect for a handholding intro.
Re: Training non-programmers in Perl regexps
by endofoctober (Initiate) on Jul 09, 2005 at 22:35 UTC
    I'm just learning Perl, but have had to deal with regexps in PHP. One thing I can definitely recommend is the Regex Coach. Once they start learning the rules for regular expressions, they'll want to test it out, and the Coach gives them something fun to work with. It also allows them to save their regex work to text files for sharing, discussion, etc.

    I'm a teacher by profession, and I know that learning for many adults can seem like a chore if they don't have something practical to work with. This software made it much easier for me to work through some of the WORST (for me, at least) regular expressions problems.

    Best of luck!
    --Jack Cole
Re: Training non-programmers in Perl regexps
by Kevad (Scribe) on Jul 09, 2005 at 21:37 UTC
    Here is a good online tutorial that goes over regexs in a general sense.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://473629]
Approved by davidrw
Front-paged by ybiC
and the pool shimmers...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2017-07-21 07:33 GMT
Find Nodes?
    Voting Booth?
    I came, I saw, I ...

    Results (319 votes). Check out past polls.