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

how to get all repeated group with regular expression

say, when I try to search and match every char from variable length
string, such as string '123456', i tried re.findall( r'(\d)*, '12346' )
, but only get '6' and Python doc indeed say: "If a group is contained
in a part of the pattern that matched multiple times, the last match is
returned."
cause the regx engine cannot remember all the past history then ? is it
nature to all regx engine or only to Python ?

Nov 21 '08 #1
1 3958
scsoce <sc****@gmail.comwrites:
say, when I try to search and match every char from variable length
string, such as string '123456', i tried re.findall( r'(\d)*, '12346'
) , but only get '6' and Python doc indeed say: "If a group is
contained in a part of the pattern that matched multiple times, the
last match is returned."
Well, re.findall(r'(\d)*', '123456') returns ['6', ''] for me, but
that's because re.findall returns the entire match, regardless of
group contents. What you probably meant was something like
re.search(r'(\d)*', '123456').group(1), which indeed returns '6', the
contents of the last group matched.

What problem are you trying to solve? Depending on this, the best
tool might be either findall/finditer, or search/match.
Nov 21 '08 #2

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

Similar topics

9
by: Leif K-Brooks | last post by:
How do I make a regular expression which will match the same character repeated one or more times, instead of matching repetitions of any (possibly non-same) characters like ".+" does? In other...
0
by: WALDO | last post by:
Assuming the following code: Dim strPattern As String = "(\d{3})(-)(\d{4})" Dim strMatch As String = "555-1234" Dim regExp As New RegEx(strPattern) Dim matches As MatchCollection =...
0
by: maersa | last post by:
hi all, i've got a group list like the following, and i'm trying to use the MatchAttribute to get the contents within the list and generate my necessary classes. ...
7
by: matteosartori | last post by:
Hi all, I've spent all morning trying to work this one out: I've got the following string: ...
4
by: Robert Dodier | last post by:
Hello all, I'm trying to find substrings that look like 'FOO blah blah blah' in a string. For example give 'blah FOO blah1a blah1b FOO blah2 FOO blah3a blah3b blah3b' I want to get three...
1
by: bitwxtadpl | last post by:
Hi, I have a simple parsing regular expression that is expecting data and a delimiter. Axy where A is the data and xy is the delimiter When the delimiter is xy it works as expected. But, when I...
4
by: DomoChan | last post by:
When I attempt to name a group in a regular expression under TR1, the library throws a non descriptive error "regular expression error". The numbered reference group works, as in /1 to reference...
0
by: Steve Holden | last post by:
Please keep this on the list. scsoce wrote: 'Fraid the Python re implementers just decided not to do it that way. regards Steve -- Steve Holden +1 571 484 6266 +1 800 494 3119...
0
by: scsoce | last post by:
MRAB wrote: Yes, you are right, but this way findall() capture only the 'top' group. What I really need to do is to capture nested and repated patterns, say, <tabletag in html contains many <tr>, ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
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...
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...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.