views:

100

answers:

6

What are the common ways to verify the given regex pattern works well of the given scenario and check the results ?

I would like to know in general , not in the particular programming language and what is the best way to learn about writing regular expression ?

+1  A: 

For testing regular expression you can use RegEx Test tools like one below :

To know more about how to learn regular expressions please check following SO threads :

Mahin
+3  A: 

I've used this resource when learning: http://www.regular-expressions.info/ and found myself going back there whenever there was something I needed to remember. It's very useful for learning and covers the basics very well. They also have various links to programs which can be used to verify regular expressions.

laura
+3  A: 

This is not a "real" verification, but RegexBuddy allows you to verify that your regex does what you expect it to do on any sample data you provide. It also translates the regex into an English description that can help to figure out mistakes. Plus, it knows all major regex flavors and can translate regexes between them.

Tim Pietzcker
+1 for hinting that "this is not a 'real' verification". You're only testing single samples with your pattern.
The Chairman
Exactly. Figuring out what you really want and then finding all relevant positive and negative test cases is the real challenge anyway. You might be able to prove that your regex works in the given scenario - but your scenario is badly defined...
Tim Pietzcker
A: 

RAD Rexexp designer is a great tool

Locksfree
+4  A: 
Yuval F
A: 

Set up an automated test using your tools of choice (because regex implementations vary from language to language and library to library) which applies the regex to a variety of both matching and non-matching inputs to verify that you get the correct results.

While RegexBuddy and the like may be helpful for initially creating the regex (or may not; I've never used them), you will still need to maintain it, just like any other code. When that time comes, it's vastly preferable to have a test script that will run through all your old test inputs (plus the new ones which created the need for the change) in a matter of seconds rather than having to sit on a website for tens of minutes, if not hours, trying to remember all your test inputs and manually re-run them to make sure you didn't break anything.

Dave Sherohman
In RegexBuddy, you can add your regular expressions in combination with their test data to a library. If you add a comment in your code mentioning the RegexBuddy library that holds the regular expression, you can instantly retrieve the regex and the test data.
Jan Goyvaerts