473,388 Members | 1,277 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,388 software developers and data experts.

Re: how to get all repeated group with regular expression

Steve Holden wrote:
Please keep this on the list.

scsoce wrote:
>Steve Holden wrote:
>>scsoce wrote:

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 ...
, 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.
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
maybe my expression was not clear. I want to capture every matched part
in a repeated pattern, not only the last, say, for string '123456', I
want to back reference any one char, not only the '6'. and i know the
example is very simple, so we can got the whole string using regx and
get every char using other python statements, but if the pattern in
group is complex?
and I test in VIM, it can do the 'back reference':
==you text in vim:
123456
== pattern:
:%s/\(\d\)*/$2
text will turn to be:
2
'Fraid the Python re implementers just decided not to do it that way.
Nor Perl.

Probably what you want is re.findall(r"(\d)", "123456"), which returns a
list of what it captured.

Nov 21 '08 #1
0 3614

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

Similar topics

2
by: Bryce Budd | last post by:
Hi all, I am trying to use a regular expression validator to check for the existence of PO Box in an address textbox. The business rule is "No addresses with PO Boxes are allowed." What I...
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...
11
by: Dimitris Georgakopuolos | last post by:
Hello, I have a text file that I load up to a string. The text includes certain expression like {firstName} or {userName} that I want to match and then replace with a new expression. However,...
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...
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...
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...
2
by: Tedmond | last post by:
Dear all, I want to read a file data block by block using regular expression. The file contents is like MWH ........ ................. ..................... MWH ....................
7
by: hellbent4u | last post by:
Hi All, I need a regular expression to be used in an ASP page which would allow a user to enter: 1000 as well as 1,000 i.e. an amount without comma as well as with comma(for example 10,000...
0
by: M.-A. Lemburg | last post by:
On 2008-11-21 15:31, scsoce wrote: ??? That's a strange requirement. If you want to match every character, then why are you using a regular expression for this ? -- Marc-Andre Lemburg
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.