re question
Moshe Zadka
moshez at math.huji.ac.il
Sat Oct 16 08:11:37 EDT 1999
[Posted and CCed to author. A tradition I will drop if it really annoys
anybody]
On Sat, 16 Oct 1999, Tim Peters wrote:
[Max M. Stalnaker]
> I have the following code:
>
> def subset(self):
> group=re.search(r"%%%([^%]+)%%%",self.data)
> self.data=group.groups(0)[0]
[the timbot]
<snipped minor improvements>
> This is much like trying to match a Python triple-quoted string with a
> regexp. Try this:
<a complex regex which does the job>
I may be missing something obvious here, but that seems to positively
/beg/ for a minimalistic match, something like:
re.compile(r'%%%(.*?)%%%')
This will result in taking everything until the *first* %%% following our
initial %%%, which was what the poster wanted.
> Regular expressions are overkill here. The above can be done quicker and
> easier via string.find:
I agree. And much, MUCH better if the text to be match grows to be more
then a couple of KBs, at which pcre will stumble somehow, if it all.
> regexps-are-to-html-as-regexps-are-to-raising-children-ly y'rs - tim
At least bot children.
next-thing-bots-will-have-a-mother-in-law-ly y'rs, Z.
--
Moshe Zadka <mzadka at geocities.com>.
INTERNET: Learn what you know.
Share what you don't.
More information about the Python-list
mailing list