Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > how to get all repeated group with regular expression

Reply
Thread Tools

how to get all repeated group with regular expression

 
 
scsoce
Guest
Posts: n/a
 
      11-21-2008
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 ?

 
Reply With Quote
 
 
 
 
Hrvoje Niksic
Guest
Posts: n/a
 
      11-21-2008
scsoce <(E-Mail Removed)> writes:

> 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Re: how to get all repeated group with regular expression MRAB Python 0 11-22-2008 03:22 PM
trying to find repeated substrings with regular expression Robert Dodier Python 4 03-14-2006 09:13 AM
Regular expression fun. Repeated matching of a group Q matteosartori@gmail.com Python 7 02-24-2006 11:49 PM
Dynamically changing the regular expression of Regular Expression validator VSK ASP .Net 2 08-24-2003 02:47 PM



Advertisments