Re: [Tutor] Re.findall question

2012-06-26 Thread Alan Gauld
On 26/06/12 23:30, Alexander Quest wrote: My question is how does Python know to return just the part in the parentheses and not to return the "blahblah" and the "yattayattayatta", etc...? If you want to know *how* Python does it you will have to read the module code (probably in C so downloa

[Tutor] Re.findall question

2012-06-26 Thread Alexander Quest
I'm a bit confused about extracting data using re.search or re.findall. Say I have the following code: tuples = re.findall(r'blahblah(\d+)yattayattayatta(\w+)moreblahblahblah(\w+)over', text) So I'm looking for that string in 'text', and I intend to extract the parts which have parentheses around

Re: [Tutor] Re.findall()

2012-04-12 Thread Andreas Perstinger
On Thu, 12 Apr 2012 09:06:53 -0700 Michael Lewis wrote: > Here's the "pattern" portion that I don't understand: > > re.findall("[^A-Z]+[A-Z]{3}([a-z])[A-Z]{3}[^A-Z]+" > You have 5 different parts here: 1) [^A-Z]+ - this matches one or more non-uppercase characters. The brackets [] describe a

Re: [Tutor] Re.findall()

2012-04-12 Thread Alan Gauld
On 12/04/12 15:47, Steven D'Aprano wrote: Regular expressions are like super-charged wildcards. In the DOS or Windows command.com or cmd.exe shell, you can use wildcards * and ? to match any characters, or a single character. In Linux and Macintosh shells, you have the same thing only even more

Re: [Tutor] Re.findall()

2012-04-12 Thread Michael Lewis
> > mjole...@gmail.com wrote: > > Hi everyone, > > > > I am having trouble understanding re.findall(). I've read through the > > documentation and looked at at some examples online, but I still don't > have > > a clear picture. > > > > I am going through pythonchallenge.com and I am on challenge 3.

Re: [Tutor] Re.findall()

2012-04-12 Thread Mark Lawrence
On 12/04/2012 14:53, mjole...@gmail.com wrote: Hi everyone, I am having trouble understanding re.findall(). I've read through the documentation and looked at at some examples online, but I still don't have a clear picture. I am going through pythonchallenge.com and I am on challenge 3. I've s

Re: [Tutor] Re.findall()

2012-04-12 Thread Steven D'Aprano
mjole...@gmail.com wrote: Hi everyone, I am having trouble understanding re.findall(). I've read through the documentation and looked at at some examples online, but I still don't have a clear picture. I am going through pythonchallenge.com and I am on challenge 3. I've see. The answer to the p

[Tutor] Re.findall()

2012-04-12 Thread mjolewis
Hi everyone, I am having trouble understanding re.findall(). I've read through the documentation and looked at at some examples online, but I still don't have a clear picture. I am going through pythonchallenge.com and I am on challenge 3. I've see. The answer to the problem, but I don't unde

Re: [Tutor] re.findall parentheses problem

2010-09-14 Thread Michael Powe
On Tue, Sep 14, 2010 at 01:09:21PM -0400, Michael Scharf wrote: > Thank you. I should have figured "groups" were the paren groups. I see it > clearly now. And your solution will work for the larger thing I'm trying to > do --- thanks. > And yes: I know this matches some non-date-like dates, b

Re: [Tutor] re.findall parentheses problem

2010-09-14 Thread Michael Scharf
Hi Evert, Thank you. I should have figured "groups" were the paren groups. I see it clearly now. And your solution will work for the larger thing I'm trying to do --- thanks. And yes: I know this matches some non-date-like dates, but the data is such that it should work out ok. Thanks again,

Re: [Tutor] re.findall parentheses problem

2010-09-14 Thread Evert Rol
> I have a regex that matches dates in various formats. I've tested the regex > in a reliable testbed, and it seems to match what I want (dates in formats > like "1 Jan 2010" and "January 1, 2010" and also "January 2008"). It's just > that using re.findall with it is giving me weird output. I

[Tutor] re.findall parentheses problem

2010-09-14 Thread Michael Scharf
Hi all, I have a regex that matches dates in various formats. I've tested the regex in a reliable testbed, and it seems to match what I want (dates in formats like "1 Jan 2010" and "January 1, 2010" and also "January 2008"). It's just that using re.findall with it is giving me weird output. I'm

Re: [Tutor] re.findall(), but with overlaps?

2005-09-03 Thread Danny Yoo
> I may put in an enhancement request to change the name of re.findall to > re.findsome. Hi Terry, A typical use of regular expressions is to break text into a sequence of non-overlapping tokens. There's nothing that technically stops us from applying the theory of regular expressions to get o

Re: [Tutor] re.findall(), but with overlaps?

2005-09-03 Thread Terry Carroll
On Sat, 3 Sep 2005, Kent Johnson wrote: > But I would say your chances of getting the name changed are slim to > none, the Python developers are extremely reluctant to make changes that > break existing code. Yeah, I know. I was mostly joking. Mostly. __

Re: [Tutor] re.findall(), but with overlaps?

2005-09-03 Thread Kent Johnson
Terry Carroll wrote: > On Sat, 3 Sep 2005, Kent Johnson wrote: > > >>AFAIK that is the way to do it. > > > I may put in an enhancement request to change the name of re.findall to > re.findsome. Or maybe findnonoverlapping. But I would say your chances of getting the name changed are slim to

Re: [Tutor] re.findall(), but with overlaps?

2005-09-03 Thread Terry Carroll
On Sat, 3 Sep 2005, Kent Johnson wrote: > AFAIK that is the way to do it. I may put in an enhancement request to change the name of re.findall to re.findsome. ___ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] re.findall(), but with overlaps?

2005-09-02 Thread Kent Johnson
Terry Carroll wrote: > But he asked me, is there a standard method to get even overlapped > strings? > > After looking through the docs, I couldn't find a way to do this in > standard methods, so I gave him a quick RYO solution: > > def myfindall(regex, seq): > > ...resultlist=[] > ...

[Tutor] re.findall(), but with overlaps?

2005-09-02 Thread Terry Carroll
A friend of mine got bitten by an expectations bug. he was using re.findall to look for all occurances of strings matching a pattern, and a substring he *knew* was in there did not pop out. the bug was that it overlapped another matching substring, and findall only returns non-overlapping str

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Liam Clarke
Sheesh. Star wars/programming humour. Better not be any Star Trek humour, that'll go over my head even further. On Tue, 15 Mar 2005 22:24:53 +, Max Noel <[EMAIL PROTECTED]> wrote: > > On Mar 15, 2005, at 21:59, Liam Clarke wrote: > > > On Tue, 15 Mar 2005 17:09:50 +, Max Noel <[EMAIL PR

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Max Noel
On Mar 15, 2005, at 21:59, Liam Clarke wrote: On Tue, 15 Mar 2005 17:09:50 +, Max Noel <[EMAIL PROTECTED]> wrote: re.findall returns a list object (as the error message says). Use name = x[1] instead. (and be careful, numbering starts from 0, so this code may contain a Kenobi error)

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Kent Johnson
Liam Clarke wrote: On Tue, 15 Mar 2005 17:09:50 +, Max Noel <[EMAIL PROTECTED]> wrote: re.findall returns a list object (as the error message says). Use name = x[1] instead. (and be careful, numbering starts from 0, so this code may contain a Kenobi error). Kenobi as in Obi Wan? or may

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Liam Clarke
On Tue, 15 Mar 2005 17:09:50 +, Max Noel <[EMAIL PROTECTED]> wrote: > > re.findall returns a list object (as the error message says). Use name > = x[1] instead. (and be careful, numbering starts from 0, so this code > may contain a Kenobi error). > Kenobi as in Obi Wan? -- 'Ther

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Max Noel
On Mar 15, 2005, at 17:41, Ron Nixon wrote: Max: Thanks that seem to do the trick. One question though, how do you write a tuple out as a list to a new file like the example I have in my code Ron You mean, all the members of the list, separated by commas, with a new line at the end? Well, this ma

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Ron Nixon
Kent: The code is below. Here's the error message. Traceback (most recent call last): File "C:/Python24/reformat.py", line 5, in -toplevel- name = x.group(1) AttributeError: 'list' object has no attribute 'group' import re f = open('reformat.txt').read() pat = re.compile(r"([^\r\n]+)\n

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Max Noel
On Mar 15, 2005, at 16:44, Ron Nixon wrote: Kent: The code is below. Here's the error message. Traceback (most recent call last): File "C:/Python24/reformat.py", line 5, in -toplevel- name = x.group(1) AttributeError: 'list' object has no attribute 'group' re.findall returns a list object (a

Re: [Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Kent Johnson
Ron Nixon wrote: Thanks to all who replied to my post earlier on re's. I'm still preplexed by why re.search and re.match works in the code below, but not re.findall. re.findall is suppose to return all non-voerlapping occurances of the pattern that matches in this example, but it returns errors. L

[Tutor] re.findall vs. re.search and re.match

2005-03-15 Thread Ron Nixon
Thanks to all who replied to my post earlier on re's. I'm still preplexed by why re.search and re.match works in the code below, but not re.findall. re.findall is suppose to return all non-voerlapping occurances of the pattern that matches in this example, but it returns errors. Looking through th