Welcome Guest [Log In] [Register]
Add Reply
Regular expressions
Topic Started: Feb 3 2008, 02:41 PM (571 Views)
Jesin
Member Avatar
The Small Fish
[ * ]
TechWizrd seems to be begging for a regex tutorial, so this is a thread for that. I don't have much time at the moment, so here's an example that matches a self-closing XML tag of the form <foo/> or <foo bar="baz" qux="quux"/> (the closing slash may or may not have whitespace before it, but not after):
Code:
 
selfclosing_tag_matcher = re.compile(r'<\w+(?:\s+\w+="(?:[^"\\]|\\.)*")*\s*/>')
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
Jesin
Feb 3 2008, 02:41 PM
TechWizrd seems to be begging for a regex tutorial, so this is a thread for that. I don't have much time at the moment, so here's an example that matches a self-closing XML tag of the form <foo/> or <foo bar="baz" qux="quux"/> (the closing slash may or may not have whitespace before it, but not after):
Code:
 
selfclosing_tag_matcher = re.compile(r'<\w+(?:\s+\w+="(?:[^"\\]|\\.)*")*\s*/>')
Well, that looks complicated, but I need no tutorial. I learn by doing. That is why I am writing ArgueBot, a pseudo-intelligent chatbot. i suggest you try him. He is amusing at best... I am improving him, son he will have the ability to actually parse language. I am going to also write him in Spainish if I can...
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
astropirate
Member Avatar
Not Lurking
[ * ]
I want to try it. Where can i find it?
You will Bow before me!

Posted ImagePosted Image
Offline Profile Quote Post Goto Top
 
techwizrd
Member Avatar
Magister ex Machina
[ *  *  * ]
astropirate
May 9 2008, 07:46 AM
I want to try it. Where can i find it?
ArgueBot was taken offline a while ago. I had started rewriting him to use natural language processing.
My DeviantArt user page Please comment and add me to your favorites!
Posted Image
Offline Profile Quote Post Goto Top
 
Deleted User
Deleted User

Dude Bunny is such a more intuitive programming language yours is so totally lame and old and groady and fat. In Bunny, you use a 15fg interface terabite lightsaber module with 12 programming petaflops of floating binary points.
Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Tutorials · Next Topic »
Add Reply