How to write this regular expression?
James Stroud
jstroud at mbi.ucla.edu
Wed May 4 13:22:32 EDT 2005
On Wednesday 04 May 2005 02:34 am, so sayeth could ildg:
> I saw someone complained that a question is too lengthy,
> and I saw some questions were complained to be unclear,
> but I never saw someone waste his time to judge if a question is a
> homework. If this is natural, I'll pay attention from now on.
>
> On 4 May 2005 01:31:48 -0700, George Sakkis <gsakkis at rutgers.edu> wrote:
> > This newsgroup is in general very helpful, but there are some
> > exceptions; one of them is when the problem appears blatantly to be a
> > homework. Perhaps if you showed that you worked on it and made some
> > progress, but it's not quite right, someone may help you.
I think by participating in this list, most of the members have felt that they
have agreed to the following unofficial terms and conditions of use:
http://www.catb.org/~esr/faqs/smart-questions.html
The interesting thing is that those who follow the letter most strictly are
usually the best ones to ask. Moreover, most members of this list are usually
looking for any excuse to compose a regular expression. In fact, they
probably come up with an answer before they make any assessments about
homework.
> I can tell you that this is not any homework at all,
> I think it by myself.
In that case, your question is free game:
>>> r = re.compile(r"_[0-3]\d?(_\d\d?){0,2}")
>>>
>>> r.search('_29_700_700000')
<_sre.SRE_Match object at 0x402ccba0>
>>> r.search('_29_50')
<_sre.SRE_Match object at 0x402f8820>
>>> r.search('_5_33')
<_sre.SRE_Match object at 0x402ccba0>
>>> r.search('_500')
>>>
James
--
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095
http://www.jamesstroud.com/
More information about the Python-list
mailing list