469,271 Members | 1,776 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,271 developers. It's quick & easy.

Clarify Regex in Python.

After may frustrated attempts I came to know that "match" function in
python re package actually start the matchs at the begining of the
subject, where "search" will find the given pattern any where in the
subject.

My Problem is, I want to know how can I force match functions to match
the pattern any location in the subject. i.e I want to turn off before
said behaviour.
Thanks In advance.

Sep 12 '06 #1
7 895
On 12 Sep 2006 05:07:03 -0700,
co************@gmail.com <co************@gmail.comwrote:
My Problem is, I want to know how can I force match functions to match
the pattern any location in the subject. i.e I want to turn off before
said behaviour.
Use search() instead; that's why the method is there.

(Or put .* at the beginning of all your patterns, though that will be
slightly slower.)

--amk
Sep 12 '06 #2
co************@gmail.com wrote:
After may frustrated attempts I came to know that "match" function in
python re package actually start the matchs at the begining of the
subject, where "search" will find the given pattern any where in the
subject.

My Problem is, I want to know how can I force match functions to match
the pattern any location in the subject. i.e I want to turn off before
said behaviour.
Thanks In advance.
Erm, is there some specific reason why you can't just use the search
method? Why does it *have* to be match()?

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden

Sep 12 '06 #3
Erm, is there some specific reason why you can't just use the search
method? Why does it *have* to be match()?

regards
Steve

I know there r many more methods to do the job, I just wonder can we
turnoff the default behaviour of match method.

Thanks.

Sep 12 '06 #4

co************@gmail.com wrote:
Erm, is there some specific reason why you can't just use the search
method? Why does it *have* to be match()?

regards
Steve


I know there r many more methods to do the job, I just wonder can we
turnoff the default behaviour of match method.
Don't wonder. Read the documentation. There is a whole section devoted
to match versus search. If you believe there are undocumented keyword
arguments to the match method and we are wantonly withholding the
information, then you should check out your theory by downloading the
source code and reading that.

HTH,
John

Sep 12 '06 #5
co************@gmail.com wrote:
I know there r many more methods to do the job, I just wonder can we
turnoff the default behaviour of match method.
that's not the "default behaviour", that's how match works. if you want
search, use search instead.

</F>

Sep 12 '06 #6
k, people, thanks for ur replys.

Sep 12 '06 #7
co************@gmail.com wrote:
After may frustrated attempts I came to know that "match" function
in python re package actually start the matchs at the begining of the
subject, where "search" will find the given pattern any where in the
subject.

My Problem is, I want to know how can I force match functions to
match the pattern any location in the subject. i.e I want to turn off
before said behaviour.
re.match = re.search

perhaps?

Stupid thing to do, but it meets the spec.

Cheers,
Terry
--
Terry Hancock (ha*****@AnansiSpaceworks.com)
Anansi Spaceworks http://www.AnansiSpaceworks.com

Sep 12 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Josef Sachs | last post: by
3 posts views Thread by gisleyt | last post: by
6 posts views Thread by Martin Evans | last post: by
10 posts views Thread by igor.kulkin | last post: by
reply views Thread by Support Desk | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.