By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,345 Members | 1,758 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,345 IT Pros & Developers. It's quick & easy.

Stupid Regex Question

P: n/a
I'm feeling dumb:

str = "<tag>text<innertag>moretext</innertag></tag><tag>text</tag>"

How can I get a list like ["text<innertag>moretext</innertag>",
"text"] using regexes? I'm starting to believe it's not possible.

Yeah, I know about the terror stories about using regexes to parse
HTML, but in this particular case, using a SAX parser would be an
horrendous overhead (I mean, it's a ridiculously simple string).

=-
Jonas Galvez
jonasgalvez.com/blog
macromedia.com/go/team

Jul 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
small loop problem?

Jonas Galvez wrote:
I'm feeling dumb:

str = "<tag>text<innertag>moretext</innertag></tag><tag>text</tag>"

How can I get a list like ["text<innertag>moretext</innertag>",
"text"] using regexes? I'm starting to believe it's not possible.

Yeah, I know about the terror stories about using regexes to parse
HTML, but in this particular case, using a SAX parser would be an
horrendous overhead (I mean, it's a ridiculously simple string).

=-
Jonas Galvez
jonasgalvez.com/blog
macromedia.com/go/team


Jul 18 '05 #2

P: n/a
Jonas Galvez:
str = "<tag>text<innertag>moretext</innertag></tag><tag>text</tag>"
How can I get a list like ["text<innertag>moretext</innertag>", "text"]
using regexes? I'm starting to believe it's not possible.


You can try with:

re.findall("<tag>(.*?)</tag>",str)

(if you don't have nested tag like in this case)
..*? means anychar (.) many times or never (*) but least as possible (?)

Greetings,
Zenzero
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.