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. 0 3615 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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,...
|
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...
|
by: matteosartori |
last post by:
Hi all,
I've spent all morning trying to work this one out:
I've got the following string:
...
|
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...
|
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...
|
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 ....................
|
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...
|
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
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
| |