[tpm] I wish I was better at regex's

Rob Janes janes.rob at gmail.com
Wed Mar 9 21:44:19 PST 2011

My ten line regex is a hand grenade?  Sounds a bit like a monty python skit.

Fulko did ask for a regex.

Personally, I got nothing against regex, complex or not.  One of the
things I like about perl is that there's a million ways to do
something.  When somebody says something is wrong, even though it
works, that just means they don't like it and that they personally
would rather do it another way.  There's no one right way to do things
in perl.

The regex solution is nice (imho), doesn't require any packages to be
installed (works out of the box), is obvious if you know regex, is
portable to any language with pcre, and is probably faster than all
the other solutions posted or suggested.  That regex doesn't use any
features that slow perl down, it just uses basic regex.

I've never used Text::Balanced before.  Sounds like it's popular, but
I gotta say the man page could be better written.  In terms of time,
it'd take me less time to write out a regex than it would to figure
out that Text::Balanced man page and write some code with it, and I
can just see a rinse and repeat cycle every time I got into it.

All you Text::Balanced aficionados, would any of you like to put up a
Text::Balanced solution to Fulko's problem?

On Wed, Mar 9, 2011 at 5:45 PM, Uri Guttman <uri at stemsystems.com> wrote:
>>>>>> "JBL" == J Bobby Lopez <jbl at jbldata.com> writes:
>  JBL> Then I suppose a rephrasing the question would be beneficial.
>  JBL> Instead of: "Strip comments from lines while obeying quoted
>  JBL> strings"
>  JBL> .. maybe:
>  JBL> "Rip key/value pairs from line, and disregard comments".
>  JBL> Which would put the focus on the key/val pairs (with an
>  JBL> opportunity to normalize them; convert them all to quoted values,
>  JBL> for example), instead of focusing on stripping the comments away.
> sometimes rephrasing the problem helps a lot. in this case it didn't
> matter to me once i saw the complex regexes being tossed about like hand
> grenades! when that was happening it was obvious to me they were going
> down the wrong path. as i said elsewhere, this is an old problem solved
> long ago by parsing left to right with a proper parser (which can use
> regexes!). the format is very similar to assembler code lines.
> uri
> --
> Uri Guttman  ------  uri at stemsystems.com  --------  http://www.sysarch.com --
> -----  Perl Code Review , Architecture, Development, Training, Support ------
> ---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

More information about the toronto-pm mailing list