[tpm] I wish I was better at regex's
uri at StemSystems.com
Wed Mar 9 12:36:13 PST 2011
>>>>> "RD" == Richard Dice <richard.dice at gmail.com> writes:
RD> Those are getting closer, but honestly this can go way beyond the
RD> realm of what regexps can provide. For example, the text in the
RD> comment area... In theory, it could contain text like
RD> "key"="Val\"ue" ; tricked you!!
RD> To fully, correctly solve this you need a full parser. Like
RD> Which is like hitting a melon with an atomic bomb.
you don't need a full parser. this can be done with Text::Balanced from
the looks of it. getting a regex to do it is insane though. just scan
from the left for each possible field. get the key=value with possible
quoted values (i don't have the spec in my head), then check for a
comment and skip/delete it. the module will handle escaped quotes and
most anything you could legally put there. this is very easy when parsed
properly and not easy with a regex.
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