473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 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 970
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
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.