Try as I might, I've never had instant recall on the details of regular expressions. For whatever reason (infrequent use, old age) the syntax just slides out of my head and onto the floor mere minutes after using it.
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: (.*)
1 year ago
11 comments:
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.
http://pyweek.org/e/RegExExpress/
For linux users, there is a similar tool called kiki (although not as feature rich).
If 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.
I 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.
http://www.ultrapico.com/Expresso.htm
Kodos does more, in that it will als ocreate the code for you; and it does it in Python!
http://kodos.sourceforge.net/
- Have fun.
Why an app? I've used retest for years.
If 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.
Thank you for the tip! Very handy.
Try Regex Buddy.
Or utilize an editor like Vim that integrates regular expressions into everyday use.
: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
for quite while ;)
Give it a try!
Cheers,
Post a Comment