Stupid Regex Question

J

Jonas Galvez

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
 
Z

ZeN0

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top