Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I frequently need to create regular expressions for use in scripts (mostly when used in sed), however, I find, sometimes the regular expressions get very complicated and difficult for me to understand and edit. Is there any software which allows one to visually creates the code for regular expressions, which I can then copy and paste into a script?

share|improve this question

6 Answers 6

up vote 6 down vote accepted

How about Visual Regexp?

http://laurent.riesterer.free.fr/regexp/screenshot2.png

share|improve this answer
    
What wm do you use? –  enzotib Dec 17 '11 at 13:54
1  
Not me, that is a link direct from the project homepage. But it looks like fvwm that was popular in the late 1990:s. Feel free to compare with something like this fvwm.org/screenshots/desktops/Helmuth_Schmelzer-1366x768/…, I have no idea what state fvwm is today (but is used to be very stable before kde and gnome was invented). –  Johan Dec 17 '11 at 20:30
1  
The window decorations are directly out of Motif, which has since been ported/copied in other window managers. en.wikipedia.org/wiki/Motif_Window_Manager –  Arcege Dec 17 '11 at 23:13

How about kregexpeditor

share|improve this answer

Try txt2regex and see if that helps. I've never used it seriously, but it seemed cool when I tried it out.

share|improve this answer

There is kodos if you prefer a standalone app. Lately I've been using online regex visualizers like http://debuggex.com or http://www.regexper.com/

share|improve this answer

Yes, text2re.com should be close to what you're looking for. Given source text, you can choose to generate a regex that matches any of the given text. The tool generates code for a smattering of languages, as well.

The regex builder UI (step 2 on the page) is slightly difficult to learn; note that hovering over any of the options explains the object against which you're matching:

regex tool UI

share|improve this answer

I'm not quite sure what you mean by "visually create the code" (do you mean a GUI tool?). If you are like me, I find it impossible to work with complex regular expressions, unless I lay them out in a structured manner, so I can get a better visual representation of the logic.

Really, sed is just a scripting language, and it can be laid out like other languages, ie. with one command per line. Here is a typical example of what I mean: A sed regex showing structured layout.

A very handy feature of sed is its debugging command l, which is a simple line dump showing the pattern space with embedded newlines shown as \n, etc..

The issue with sed is not just the regular expressions. It has a funky cryptic set of commands for looping and condition testing; this takes time to get used to... The best tool I've ever found to assist me with dealing with sed is quite simply: I read the manual in detail.. From that, it is just a process of starting small and getting the simple things working; then build up to bigger things to gain experience..

Perl regex has some useful features to assist in laying out complex patterns; eg. the ability to ignore whitespace in your expression.. (As a challenge, and for the expereince factor, I wrote a sed parser to parse my sed code to allow such whitespace... PS. I don't need it now; because of the experience :) Actually just laying out commands, one per line, is almost as good as the perl feature.

The best tool to help you is: experience. eg. Tackling the regex questions on this site is a great way to get that experience... I feel that GUI tools don't really help much, because they inhibit the experience...

In summary, the best helper tools are experience and structured layout, and read the manual (in detail)..

I've used the word "expereince" a lot.. by it I mean that the act of preparing regular-expressions (and in the case of sed, any looping logic etc.) is the key factor.. "Regex-Builder" type tools; don't write the regex for you; they only test it, and they certainly won't handle sed's program logic, because that isn't a regex..(and you have specifically singled out sed)... The syntax-highlighting they may offer doesn't do much for me. An editor with good bracket matching is pretty handy though (I use emacs)..

share|improve this answer
    
I think it doesn't hurt if you have a tool for easy testing and experiment. (emacs re-builder) –  favadi Dec 17 '11 at 4:57
1  
I've used emacs re-builder and it did't help me at all ... not past day 1 ...All it showed me is that in emacs it needs an extra backslash or two, because of how emacs evaluates things... You can make the same test by evaluating your regex via C-x C-e.. It doesn't write the expression for you; you still need to write it... And then there is the emacs system of writitng a regex by using descriptive words.. (I thought that verbose/english-like system died out with COBOL.. but even COBOL isn't completely dead, yet) .. and regardles, you still need to write it. –  Peter.O Dec 17 '11 at 5:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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