[tpm] I wish I was better at regex's
Shaun Fryer
sfryer at sourcery.ca
Wed Mar 9 11:46:42 PST 2011
or take the managerial approach and just tell people not to do weird
things in their keys/values/comments. there's only so much heuristics
which can reasonably/practically be applied to such a relatively
simple problem. it's far less effort to strike the human element first
and foremost.
--
Shaun Fryer
cell: 1-647-709-6509
voip: 1-647-723-2729
On Wed, Mar 9, 2011 at 2:42 PM, Richard Dice <richard.dice at gmail.com> wrote:
> Those are getting closer, but honestly this can go way beyond the realm of what regexps can provide. For example, the text in the comment area... In theory, it could contain text like
>
> "key"="Val\"ue" ; tricked you!!
>
> To fully, correctly solve this you need a full parser. Like Parse::RecDescent
>
> Which is like hitting a melon with an atomic bomb.
>
> If you have ANY foreknowledge of the sorts of files you are going to receive and the kind of comments they will (NOT "might, theoretically") contain, just cook up some cheap-ass line mangling logic, maybe using some regexps, maybe some substr and index and rindex.
>
> Sent from my iPhone
>
> On 2011-03-09, at 2:32 PM, Fulko Hew <fulko.hew at gmail.com> wrote:
>
>> On Wed, Mar 9, 2011 at 2:29 PM, Shaun Fryer <sfryer at sourcery.ca> wrote:
>>>
>>> It's very difficult to do without matching quotes, and hence key/value
>>> pairs. For instance, what if the comment contains a quote, just as the
>>> quotes may contain a semi-colon? In this case I've sidestepped the
>>> problem of escaped quotes by using a word-boundary (\b) match inside
>>> any matched quotes. the side effect of this, is that any spaces inside
>>> the quotes will count...
>>>
>>> good luck if you can do it without matching keys/values/quotes. I've
>>> already got beers riding on the solution. ;)
>>
>> Thats why I then looked at things like:
>>
>> Regexp::Common::balanced
>> Regexp::Common::comment
>>
>> but I couldn't figure out how to apply them.
>> _______________________________________________
>> toronto-pm mailing list
>> toronto-pm at pm.org
>> http://mail.pm.org/mailman/listinfo/toronto-pm
>
More information about the toronto-pm
mailing list