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?

- 829,060

- 5,035
- 15
- 50
- 84
8 Answers
How about Visual Regexp?

- 4,583
-
What wm do you use? – enzotib Dec 17 '11 at 13:54
-
1Not 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 http://www.fvwm.org/screenshots/desktops/Helmuth_Schmelzer-1366x768/screenshot.png, 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
-
1The window decorations are directly out of Motif, which has since been ported/copied in other window managers. http://en.wikipedia.org/wiki/Motif_Window_Manager – Arcege Dec 17 '11 at 23:13
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/
Not exactly what OP asks for - but I think it's relevant, so I'll cross post Recommendation for Regex editor? #549107 - Ask Ubuntu:
Here's my attempt at a visual regex GUI tool, called visRegexTester.py
:
It has a "live preview" ("Auto rerun") if you type and change the "regex" field. Otherwise it's just that single file; there is a README comment at start - here's a snippet from it:
visRegexTester is a small Python/Tkinter GUI application to assist with writing of regular expressions; tested with Python 2.7 and 3.2. In fact, it is merely an interface for other command line programs: it exploits the fact that a lot of Unix/GNU/Linux programs used as regex processors in the terminal (e.g.
grep
,sed
,perl
), have a similar command-line syntax in three parts:(PROGRAM --ARGS) ('REGEX') (FILENAME)
... see the rest of it for more. The screenshot:
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:

- 449
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)..
-
I think it doesn't hurt if you have a tool for easy testing and experiment. (emacs re-builder) – favadi Dec 17 '11 at 04:57
-
1I've used
emacs re-builder
and it did't help me at all ... not past day 1 ...All it showed me is that inemacs
it needs an extra backslash or two, because of how emacs evaluates things... You can make the same test by evaluating your regex viaC-x C-e
.. It doesn't write the expression for you; you still need to write it... And then there is theemacs
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 05:15
If a web app (that works offline, after loading) qualifies, nice one is regex101.com.

- 3,231