http://www.perlmonks.org?node_id=34552


in reply to Regexes vs. Maintainability

This is purely anecdotal, of course, but regexes are just plain fun - to write, anyway. Supporting other people's can be a major source of annoyance. How many of them are really understandable to the average coder?

Personally, I prefer a general comment and then comments on specific parts only if the expression is particularly intricate (as in the example above). In any case, I would be interested to see how many people really bother to comment their regexes beyond "parses $var" or some such thing. I'm sure there are plenty of horror stories floating around.

Replies are listed 'Best First'.
RE: Re: Regexes vs. Maintainability
by mirod (Canon) on Sep 29, 2000 at 11:46 UTC

    I tend to comment regexps like this:

    $path=~/^\s*([\w-]+) # elt \s*\[\s*\@ # [@ ([\w-]+) # att $1 \s*=\s*(["']) # = " (or ',) $2 (.*?) # value $3 \3\]\s*$/gx) # "] (or ')

    It works very well for moderately complex regexps.