Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

What are the best resources you've found for learning regular expressions?

share|improve this question
    
    
    
I would love it if someone would post a link to a site where I could copy/paste test strings and a regex and it would tell me if it passes or not. I'm sure I could build my own, but a web page is so much easier and accessible from any machine. –  Rachel Feb 18 '11 at 14:44
    
Jeff Atwood recommends the O'Reilly book. While I can't comment on that particular book, I have had good success with several other O'Reilly books. –  Michael K Feb 18 '11 at 14:54
    
@Rachel: Try myregexp.com. –  Michael K Feb 18 '11 at 14:58
show 1 more comment

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

closed as not constructive by Jim G., gnat, Walter, Martijn Pieters, Kilian Foth Jan 25 '13 at 12:03

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

6 Answers

IMHO the best book is Mastering Regular expressions

Besides that download the regulator and start experimenting, the regulator has a nice menu that can put in the actual parts of the regex so you learn what the parts are called and in time you will stop using the menu and type the regex yourself, also the analyzer trys to write out the regex in english. Be aware though the regulator has quirks and might crash often.

Next go to regular-expressions.info for a lot of help.

Last go to regexlib.com for examples

25-1-2013 Edit: a while back Expresso was made available for free. It has less quirks than the regulator and just works great. Highly recommended.

Hope this helps

share|improve this answer
1  
I'll throw in my preference for Expresso: ultrapico.com/Expresso.htm –  FrustratedWithFormsDesigner Feb 18 '11 at 14:51
add comment

I tried to do here a list of resources that have been useful for me. I haven't read a book, I found all my knowledge online

Online

Online Regex Tester

  • Regexr, my favourite one (don't know the engine, but supports look behinds, so an advanced one.) Has also a regex community library and explain regex constructs
  • Rubular, based on Ruby
  • Regular Expression Analyzer, give it a regex and it will analyze it
  • Refiddle, you can choose the regex engine (JavaScript, Ruby, .NET)

Applications

share|improve this answer
    
+1 for Regexr - I find myself going back there on an almost daily basis. –  MattDavey Jan 25 '13 at 9:00
add comment

Depends how deep understanding of them do you need.

If you'd really want to understand them, you should take in account that regular expressions are one of notations for context-free grammars. Which in turn are directly related to finite-state automata.

I've learned about these from classical book:

John E. Hopcroft, Rajeev Motwani, Jeffrey D. Ullman Introduction to automata theory, languages, and computation

share|improve this answer
add comment

I like RegexBuddy. Not free, but it has saved me a lot of time.

Can be configured to mimic regular expression syntax used by C#, VB.NET, VB 6, Delphi, Java, Perl, PHP, JavaScript, VBScript, Python, Ruby, Tcl and C/C++. Customer support is excellent (had a question, got an answer right away by email). There is also a user forum.

I have no connection witht he company, just a satisfied customer.

share|improve this answer
    
+1 - regexbuddy is great during the learning phase. –  Erik Feb 18 '11 at 19:01
add comment

I do not know what level you are currently on and this is not a reasource actually, but - for me the best learning breakthrough was usage of http://weitz.de/regex-coach/ - a program that shows matching in realtime. This realtime response allowed me to finally really understand the basic ideas of using regexps, which I could not get from any resource prior to that

There's other similar software and also web-based alternatives (regexr probably) etc.

share|improve this answer
add comment

Steps and Resources For Learning The Art of Regex

disclaimer: this is an opinion based on research and comparisons between alternatives!


1. Understand Proper and Improper Usage

2. Learn, then Experiment and Reference the Syntax

3. Maintain Them: Expresso (free) or RegexBuddy ($40) or RegexMagic ($40)

  • Always encapsulate regular expressions in a function with a descriptive name

5. Master and Optimize Them

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.