469,929 Members | 1,817 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,929 developers. It's quick & easy.

re - multiple results

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
Jul 19 '05 #1
2 1055
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
Jul 19 '05 #2
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>

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by Andrae Muys | last post: by
66 posts views Thread by Darren Dale | last post: by
2 posts views Thread by pengbsam | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.