tags:

views:

3716

answers:

12

Does anyone have any good link to a website or a good tool to create regular expressions rather than break your head to create one. The tool should be able to create regular expressions by simply selecting some sort of pattern text. For e.g If I want a phone number to be validated, I should be able to enter (000)-(111)-(1111) or 000-000-0000 or 000-0000000 and the tool shold generate regular expression automatically..

A: 

Expresso has a regex GUI builder.
But I'd recommend putting some time in and learning regular expressions - you'll be able to create expressions much faster than with a helper-builder-GUI

Edit: But it still won't read your mind. You need to build the regex piece by piece.. in that I want 3 digits then a - and so on... It can't guess that you need a phone number given a matching string

Gishu
I'm actually a regexp seasoned developer. What I'll like to do is provide this to some extend to some users. We have a HUGE dataset and they will benefit from running "grep-like" finds on it, but they are not as technically inclined, thoughts on that?
Jorge Vargas
@Jorge - Regular Expression is a DSL for searching text.. Maybe you can build your own language on top of it. So examine what kinds of searches are common among your end-users, then help them via an app that generates the right reg-exp. e.g. if they routinely perform 'show me all lines that begin with ERROR!' - you could give them an app that has a menu/command 'Search lines beginning with...', ask them to enter the substring e.g. ERROR! and click Find. Behind the scenes you execute /^ERROR!(.*)/ and print the first group. Wrap all commonly used-searches in this manner.
Gishu
The problem I see with that approach is that you are building a language on top of another language and the potential for getting screwed is very high.
Jorge Vargas
@Jorge - reg exp is pretty stable (as you might well know) if that is your concern.
Gishu
and it is so full of special characters that building it is a parsing nightmare.
Jorge Vargas
+5  A: 

Creating regular expressions without having any clue about them doesn't work. But you can make use of software that helps you create them. I heard that regexbuddy should be quite good.

EDIT

Reasons why creating regexes from arbitrary strings cannot work can be found in the answer to this question

soulmerge
I am a fan of Regex Buddy! Pretty cheap, and quite useful!
geoffc
I'm not. I'll admit that I've only seen one example of it's use, but the regex it generated was downright hideous - at least twice as long as the solutions people came up with. RegexBuddy may be cheap, but learning how to use regular expressions is free, and the knowledge is priceless.
Chris Lutz
That is absolutely correct, auto-generated regular expressions are to be regarded just like any auto-generated code: cheap development, bad runtime.
soulmerge
+1 for the nice link. The second answer to that question is excellent.
Chris Lutz
+2  A: 

The human brain will create better and more readable regexes than any RegexBuddy. Regardless of how much a piece of software may help you develop faster regexes, there are several problems you'll have with these regexes:

  1. They'll probably look pretty awful, and enforce the idea of regexes as write-only.
  2. They'll probably be inefficient, and use weird/unnecessary solutions.
  3. You won't understand what's going on in the regex, which means you'll be a cargo-cult programmer.

In the end, learning regular expressions will make you a better programmer - you'll be able to read other people's code and understand what it does, as well as being able to write your own regexes on the fly, which will usually be faster than stopping your coding workflow, turning to some external program, coming up with a list of test cases that should pass or fail, and then copying and pasting the resulting generated regex into your code without knowing what it does.

Chris Lutz
Any reason for downvoting my advice, which has been echoed in a weaker sense in half the answers posted? Or just mad that I won't recommend a quick-fix for a lack of regex knowledge?
Chris Lutz
+1 for making perfect sense.
Josh
A: 

RegexDesigner.NET is a very stripped down tool that I use when I don't have complex expressions to make. Less clutter makes simple regex testing fast.

Will
+1  A: 

I'm also a fan of RegexBuddy, but if you're working on a tight budget you can also use the open source (and free) utility called Kodos. It was originally designed for debugging and creating regular expressions for Python, but you can use it to validate any regular expression.

Of course, it will still rely on you actually knowing how to construct the regex, but at least you can use it to validate or test what you have.

Andre Miller
Is there a rule that SO users under a certain rep can't add hyperlinks? If so, that's ridiculous. Anyway, I added the link for you. There's a button that has a globe and an arrow. Click on that and enter the URL to link to. It will give you something like "[][1]", and a footnote "[1]URL". Put the link text in between the first "[]". You can look at your post now and see exactly how it's done.
Chris Lutz
Yeah, there must be. I did have the link there before but when I tried to submit it a popup message told me new users can't have hyperlinks, so I removed it again.Thanks for the edit!
Andre Miller
A: 

I'm surprised no one has mentioned Regexlib yet

idstam
+6  A: 

Here is a good online regex tool: www.gskinner.com/RegExr/

RegExGuru
I find that one very limiting. And it's horrible as it steals the focus and you can't tab away from it. Anyone up to coding a replacement ?
Jorge Vargas
A: 

The Regex Coach has helped me a lot - it supports pretty much all the intricacies of regular expressions; you see in real time how your modifications operate on the string; also has a visual representation of the parse tree.

Piskvor
A: 

I like the highlighting and additional functionality in RegexPal. It's a free web tool that has a quick reference easily accessible. You'll even notice at the bottom that they recommend RegexBuddy for more power, but you'll still find RegexBuddy functionality in the web app.

Doomspork
+1  A: 

If you're using Eclipse then Regex Util by Sergey Evdokimov is a pleasure. It sits right there in your IDE, so you won't lose it, and provides instant feedback on matches. Then it does all the escaping/unescaping for you as you copy and paste it back and forth into your code.

Josh
+4  A: 

I use Rubular. It is not just for Ruby.

Gerhard
Good one at last!!
chugh97
Bookmarked this one. I needed a simple regex and have little knowledge, not to say none. I was done in a few minutes with this editor and its "quick references".
DrDro