Connecting Tech Pros Worldwide Help | Site Map

Re: how to get all repeated group with regular expression

  #1  
Old November 21st, 2008, 03:05 PM
Steve Holden
Guest
 
Posts: n/a
scsoce wrote:
Quote:
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' )
I think you will find you missed a quote out there. Always better to
copy and paste ...
Quote:
, 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."
So use

r'(\d*)'

instead and then the group includes all the digits you match.
Quote:
cause the regx engine cannot remember all the past history then ? is it
nature to all regx engine or only to Python ?
Different regex engines have different capabilities, so I can't speak to
them all. If you wanted *all* the matches of *all* groups, how would you
have them returned? As a list? That would make the case where there was
only one match much tricker to handle. And what would you do with

r'((\w)*\d)*)'

Also, what about named groups? I can see enough potential implementation
issues that I can perfectly understand why Python works the way it does,
so I'd be interested to know why it doesn't makes sense to you, and what
you would prefer it to do.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: how to get all repeated group with regular expression M.-A. Lemburg answers 0 November 21st, 2008 05:45 PM
Re: how to get all repeated group with regular expression MRAB answers 0 November 21st, 2008 05:45 PM
Re: how to get all repeated group with regular expression Steve Holden answers 0 November 21st, 2008 04:35 PM
how to get all repeated group with regular expression scsoce answers 1 November 21st, 2008 03:05 PM