Awhile back a co-worker introduced me to The Regex Coach, and I've used it regularly ever since. Paste in a snippet of text, type a regex pattern, and it highlights matches in the text as you type. Super easy way to (re)learn or explore regex.
It's targeted at Perl-style regex, which for me has proved completely compatible with Python's re module. If you like it, don't forget to donate.
A bonus tip for the regex-challenged like myself...
If you memorize only one thing: (.*)
It's probably not as fleshed out as your friend's trainer but someone made a game out of regex in a previous PyWeek game programming contest.
ReplyDeletehttp://pyweek.org/e/RegExExpress/
For linux users, there is a similar tool called kiki (although not as feature rich).
ReplyDeleteIf you want to really learn regexes, though, or want a reference, try «Mastering Regular Expressions» from O'Reilly.
You really shouldn't use regular expressions to extract information from XML documents.
ReplyDeleteI know it's just an example, but it's suggestive, both of what you may be using regular expressions for and what other people may think regular expressions are useful for.
Use an XML parser. The ad-hoc regular expression you write is almost certainly harder, slower, and worst of all, wrong.
Expresso is even better. But, it's only on Windows, I think.
ReplyDeletehttp://www.ultrapico.com/Expresso.htm
Kodos does more, in that it will als ocreate the code for you; and it does it in Python!
ReplyDeletehttp://kodos.sourceforge.net/
- Have fun.
Why an app? I've used retest for years.
ReplyDeleteIf you have python & a browser, you can use it locally. Otherwise, there's a web version.
--Hal
The regex app and retest doesn't seem so much alike? The regex app you can highlight what you want the expression to match. Retest is only a tester for the expressions.
ReplyDeleteThank you for the tip! Very handy.
ReplyDeleteTry Regex Buddy.
ReplyDeleteOr utilize an editor like Vim that integrates regular expressions into everyday use.
ReplyDelete:set incsearch
for incrementa searches
to start the search use / so your expression would be.
/^.\+foo.\+$
I´ve been using this http://gskinner.com/RegExr
ReplyDeletefor quite while ;)
Give it a try!
Cheers,