Txt2regex is a regular expression wizard for the command line.
Users with little or no knowledge of regular expressions can quickly create hairy regexes by answering questions in a simple text-based interactive interface.
Txt2regex is aware of the particular notation and caveats of many different regular expression flavors, generating valid regexes for more than 20 targets, including grep, sed, Vim, Emacs, JavaScript, Python, PHP, PostgreSQL.
Txt2regex is a one-file shell script made 100% with Bash builtin commands. The only requirement is Bash itself, since no grep, find, sed or any other system command is used.
Download: txt2regex 0.9 (released May 21, 2020) - Changelog
License: GPLv2
Doc: Manual Page
GitHub: https://github.com/aureliojargas/txt2regex
Supported targets (22)
Text editors:
- ed
- Emacs
- vi
- Vim
Tools:
- AWK
- egrep
- expect
- find
- gawk
- grep
- lex
- mawk
- procmail
- sed
Databases:
- MySQL
- PostgreSQL
Programming languages:
- CHICKEN Scheme
- JavaScript
- Perl
- PHP
- Python
- Tcl
Features
Support for POSIX classes, such as [:alpha:]
, [:lower:]
and friends:
Support for groups, including nested groups and a nice balance control on the number of opened/closed groups:
Full support for localization, this is the Spanish translation:
Option --showmeta
shows a complete table for all the supported metacharacters used in all the supported flavors:
$ ./txt2regex.sh --showmeta awk + ? | () awk version 20121220 chicken + ? {} | () CHICKEN 4.12.0 ed \+ \? \{\} \| \(\) GNU Ed 1.10 egrep + ? {} | () grep (GNU grep) 3.1 emacs + ? \\{\\} \\| \\(\\) GNU Emacs 25.2.2 expect + ? {} | () expect version 5.45.4 find + ? {} | () find (GNU findutils) 4.7.0-git gawk + ? {} | () GNU Awk 4.1.4 grep \+ \? \{\} \| \(\) grep (GNU grep) 3.1 javascript + ? {} | () node v8.10.0 lex + ? {} | () flex 2.6.4 mawk + ? | () mawk 1.3.3 Nov 1996 mysql + ? {} | () mysql Ver 14.14 Distrib 5.7.29 perl + ? {} | () perl v5.26.1 php + ? {} | () PHP 7.2.24-0ubuntu0.18.04.4 postgres + ? {} | () psql (PostgreSQL) 10.12 procmail + ? | () procmail v3.23pre 2001/09/13 python + ? {} | () Python 3.6.9 sed \+ \? \{\} \| \(\) sed (GNU sed) 4.4 tcl + ? {} | () tcl 8.6 vi \{\} \(\) nvi 1.81.6-13 vim \+ \= \{} \| \(\) VIM - Vi IMproved 8.0 (2016 Sep 12) NOTE: . [] [^] and * are the same on all programs. $
Option --make
shows handy ready-to-use regexes for common patterns, such as a regex to match a date:
$ ./txt2regex.sh --make date2 ### date LEVEL 2: mm/dd/yyyy: matches from 00/00/1000 to 19/39/2999 Regex python: [01][0-9]/[0123][0-9]/[12][0-9]{3} Regex egrep : [01][0-9]/[0123][0-9]/[12][0-9]{3} Regex grep : [01][0-9]/[0123][0-9]/[12][0-9]\{3\} Regex sed : [01][0-9]/[0123][0-9]/[12][0-9]\{3\} Regex vim : [01][0-9]/[0123][0-9]/[12][0-9]\{3} Regex emacs : [01][0-9]/[0123][0-9]/[12][0-9]\\{3\\} $
For a complete list of all the command line options and features, please see the following documents:
- https://github.com/aureliojargas/txt2regex/blob/main/tests/cmdline.md
- https://github.com/aureliojargas/txt2regex/blob/main/tests/features.md
Packages
Txt2regex is a stand-alone Bash script, it doesn't need to be installed. But if you want to try it effortlessly using your package manager, it's available for some systems:
- RPM package (Fedora, OpenMandriva, EPEL)
- Debian package (Debian, Ubuntu)
- Gentoo Linux
- Fink for macOS
Magazine/site reviews
date | source | page | link |
---|---|---|---|
Dez 2004 |
Linux Magazine (Brazil) | 82, 83 | PDF (Portuguese) |
Oct 2004 |
ComputerWoche.de site | - | Original review (German) |
Oct 2004 |
Linux Magazine (International) | 76, 77 | |
Set 2004 |
Linux User (Germany) | 66, 67 | - |
Dec 2003 |
Slashdot Japan | - | Original review (Japanese) |
Oct 2003 |
Server Watch site | - | Original review |
May 2002 |
ASCII's Linux Magazine | 123 | Scanned page (Japanese) |
Feb 2002 |
UnixReview.com site | - | Original review |
Nov 2001 |
ASCII's Linux Magazine | 141 | Scanned page (Japanese) |
Apr 2001 |
Linux Format Magazine | 47 | Scanned page |