472,358 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,358 software developers and data experts.

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 934
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Josef Sachs | last post by:
Is Andrew Kuchling's regex-to-re HOWTO available anywhere? I've found the following (dead) links on various Web pages: http://py-howto.sourceforge.net/regex-to-re/regex-to-re.html...
75
by: Xah Lee | last post by:
http://python.org/doc/2.4.1/lib/module-re.html http://python.org/doc/2.4.1/lib/node114.html --------- QUOTE The module defines several functions, constants, and an exception. Some of the...
3
by: gisleyt | last post by:
I'm trying to compile a perfectly valid regex, but get the error message: r = re.compile(r'(*)(\d{1,3}\.\d{0,2})?(\d*)(\,\d{1,3}\.\d{0,2})?(\d*)?.*') Traceback (most recent call last): File...
6
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead"....
8
by: Xah Lee | last post by:
the Python regex documentation is available at: http://xahlee.org/perl-python/python_re-write/lib/module-re.html Note that, i've just made the terms of use clear. Also, can anyone answer what...
10
by: igor.kulkin | last post by:
I have a small utility program written in Python which works pretty slow so I've decided to implement it in C. I did some benchmarking of Python's code performance. One of the parts of the program...
2
by: voxiac | last post by:
Could someone tell me why: Fails with message: Traceback (most recent call last): File "<pyshell#12>", line 1, in <module> re.compile('\\dir\\(file)') File "C:\Python25\lib\re.py", line 180,...
0
by: Support Desk | last post by:
That’s it exactly..thx -----Original Message----- From: Reedick, Andrew Sent: Tuesday, June 03, 2008 9:26 AM To: Support Desk Subject: RE: regex help The regex will now skip anything with...
4
by: seberino | last post by:
I'm looking over the docs for the re module and can't find how to "NOT" an entire regex. For example..... How make regex that means "contains regex#1 but NOT regex#2" ? Chris
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it so the python app could use a http request to get...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.