473,327 Members | 2,065 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,327 software developers and data experts.

Regular Exp

If I want to match $.58 in $.589922 How do I do it with Regular Expressions?
s=re.search("\$\.[0-9]{2}", "$.589922")
s.string

'$.589922'
and not
'$.58' which i s what I want
I think it has something to do with Greediness right?
Jul 18 '05 #1
4 2122
On Fri, 31 Oct 2003 08:11:39 GMT, afds wrote:
If I want to match $.58 in $.589922 How do I do it with Regular Expressions?
s=re.search("\$\.[0-9]{2}", "$.589922")
s.string '$.589922'
Yes. The 'string' member of a MatchObject returns the entire string
that was passed to the search() that produced it, as the docs will tell
you:

<http://www.python.org/doc/current/lib/match-objects.html#l2h-875>
and not
'$.58' which i s what I want


You need to define one or more groups within the expression, grouping
what you want to access. Then use 'MatchObject.group()' to access one
group at a time or 'MatchObject.groups()' to access all of them as a
tuple:
s = re.search( "(\$\.[0-9]{2})", "$.589922" )
s.group(1) '$.58' s.groups() ('$.58',)


--
\ "I used to be a proofreader for a skywriting company." -- |
`\ Steven Wright |
_o__) |
Ben Finney <http://bignose.squidly.org/>
Jul 18 '05 #2
On 31 Oct 2003 19:29:14 +1050, Ben Finney wrote:
You need to define one or more groups within the expression, grouping
what you want to access. Then use 'MatchObject.group()' to access one


Or, as Harvey pointed out, use 'MatchObject.group(0)' to access the
entire matching portion of the string, without needing to explicitly
define groups.

--
\ "Any sufficiently advanced bug is indistinguishable from a |
`\ feature." -- Rich Kulawiec |
_o__) |
Ben Finney <http://bignose.squidly.org/>
Jul 18 '05 #3
Ah, so you're saying my Regular Expression is correct? It just matches for
two digits?

"Ben Finney" <bi****************@and-benfinney-does-too.id.au> wrote in
message news:sl*******************************@rose.locald omain.fake...
On 31 Oct 2003 19:29:14 +1050, Ben Finney wrote:
You need to define one or more groups within the expression, grouping
what you want to access. Then use 'MatchObject.group()' to access one


Or, as Harvey pointed out, use 'MatchObject.group(0)' to access the
entire matching portion of the string, without needing to explicitly
define groups.

--
\ "Any sufficiently advanced bug is indistinguishable from a |
`\ feature." -- Rich Kulawiec |
_o__) |
Ben Finney <http://bignose.squidly.org/>

Jul 18 '05 #4
Damn didn't see Harvey's message, ignore.
Ah, so you're saying my Regular Expression is correct? It just matches for two digits?

"Ben Finney" <bi****************@and-benfinney-does-too.id.au> wrote in
message news:sl*******************************@rose.locald omain.fake...
On 31 Oct 2003 19:29:14 +1050, Ben Finney wrote:
You need to define one or more groups within the expression, grouping
what you want to access. Then use 'MatchObject.group()' to access one


Or, as Harvey pointed out, use 'MatchObject.group(0)' to access the
entire matching portion of the string, without needing to explicitly
define groups.

--
\ "Any sufficiently advanced bug is indistinguishable from a |
`\ feature." -- Rich Kulawiec |
_o__) |
Ben Finney <http://bignose.squidly.org/>


Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
3
by: Jamie Pittman via AccessMonster.com | last post by:
I am having trouble bellow wit this query. I have the total regular hours and the overtime. The problem is that if it is 8 hours and under, I need it to show as regular hours. Any thoughts? ...
4
by: Buddy | last post by:
Can someone please show me how to create a regular expression to do the following My text is set to MyColumn{1, 100} Test I want a regular expression that sets the text to the following...
4
by: Neri | last post by:
Some document processing program I write has to deal with documents that have headers and footers that are unnecessary for the main processing part. Therefore, I'm using a regular expression to go...
2
by: Sehboo | last post by:
Hi, I have several regular expressions that I need to run against documents. Is it possible to combine several expressions in one expression in Regex object. So that it is faster, or will I...
4
by: Együd Csaba | last post by:
Hi All, I'd like to "compress" the following two filter expressions into one - assuming that it makes sense regarding query execution performance. .... where (adate LIKE "2004.01.10 __:30" or...
7
by: Billa | last post by:
Hi, I am replaceing a big string using different regular expressions (see some example at the end of the message). The problem is whenever I apply a "replace" it makes a new copy of string and I...
9
by: Pete Davis | last post by:
I'm using regular expressions to extract some data and some links from some web pages. I download the page and then I want to get a list of certain links. For building regular expressions, I use...
25
by: Mike | last post by:
I have a regular expression (^(.+)(?=\s*).*\1 ) that results in matches. I would like to get what the actual regular expression is. In other words, when I apply ^(.+)(?=\s*).*\1 to " HEART...
1
by: Allan Ebdrup | last post by:
I have a dynamic list of regular expressions, the expressions don't change very often but they can change. And I have a single string that I want to match the regular expressions against and find...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.