Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > re - multiple results

Reply
Thread Tools

re - multiple results

 
 
Pingveno
Guest
Posts: n/a
 
      06-10-2005
I'm working on the Python Challenge (make sure to try it:
http://www.pythonchallenge.com). One of the puzzles requires the use of
regular expressions, but with multiple matches in the text. I tried to
use re.findall(), but I only go one result instead of a list of results.

>>> print re.findall(r"myexpression",text)

['AZBaCTR']

There should, of course, be several matches. What function should I use?
Or is it not a function issue?

Thanks,
Pingveno
 
Reply With Quote
 
 
 
 
Michael Hoffman
Guest
Posts: n/a
 
      06-10-2005
Pingveno wrote:
> I'm working on the Python Challenge (make sure to try it:
> http://www.pythonchallenge.com). One of the puzzles requires the use of
> regular expressions, but with multiple matches in the text. I tried to
> use re.findall(), but I only go one result instead of a list of results.
>
>>>>print re.findall(r"myexpression",text)

>
> ['AZBaCTR']
>
> Or is it not a function issue?


Works for me. Although I usually prefer this idiom:

re_something = re.compile(r"pattern")
re_something.findall(text)

You're doing something else wrong.
--
Michael Hoffman
 
Reply With Quote
 
 
 
 
Fredrik Lundh
Guest
Posts: n/a
 
      06-13-2005
Pingveno wrote:

> I'm working on the Python Challenge (make sure to try it:
> http://www.pythonchallenge.com). One of the puzzles requires the use of
> regular expressions, but with multiple matches in the text. I tried to
> use re.findall(), but I only go one result instead of a list of results.
>
>>>> print re.findall(r"myexpression",text)

> ['AZBaCTR']
>
> There should, of course, be several matches.


"myexpression" won't return "AZBaCTR" for any kind of input, so I'm not
sure what "of course" really refers to...

> What function should I use? Or is it not a function issue?


my guess is that you're using "*" or "+" in a situation where you don't really
need them. cf.

>>> re.findall("\w", "abcdef")

['a', 'b', 'c', 'd', 'e', 'f']
>>> re.findall("\w+", "abcdef")

['abcdef']

</F>



 
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
Using ajax call to fetch multiple results from multiple queries and showing them 1 by 1 as the results comes. Biranchi Narayan Panda ASP .Net 0 02-21-2010 03:46 PM
How can I make this more efficient? (combining DataSet results with the results of a DB lookup.) Ken Fine ASP .Net 3 07-23-2008 08:11 AM
Prefix increment/decrement results in lvalue, but postfix one results in rvalue? lovecreatesbeauty C++ 8 09-12-2005 10:23 PM
Displaying results as "pages" of a JTable and sorting across all results ... Monique Y. Mudama Java 1 06-28-2005 01:01 AM
getting multiple table results question using stored procedure Patrick Olurotimi Ige ASP .Net 2 05-09-2005 10:57 AM



Advertisments