Grep/Sed Regex Tester

Test a POSIX regex against sample text. Matches are highlighted live, with the grep and sed commands generated below.

Flavor cheat sheet: in BRE the operators + ? | ( ) { } are literal characters and need a backslash to act as operators (\+ \? \| \( \) \{ \}). In ERE they work unescaped, like most modern regex. Character classes [a-z], anchors ^ $, dot . and star * behave the same in both. This tester translates your POSIX pattern to JavaScript regex internally, which covers everyday grep/sed patterns; exotic constructs like [[:alpha:]] are translated for the common classes, and backreference behavior may differ slightly from GNU tools.

Grep/Sed Regex Tester

Most online regex testers speak JavaScript or PCRE, then your pattern fails the moment it meets grep. The reason is flavor: classic grep and sed use POSIX Basic Regular Expressions, where +, ?, |, parentheses and braces are literal characters unless you escape them. This tester is built for exactly that world.

Type a pattern, pick BRE or ERE, and edit the sample text or paste your own. Matching lines highlight instantly with each match marked, non-matching lines dim so you can scan results at a glance, and a counter reports how many lines and how many total matches you got. Flip on the -i box for case-insensitive matching or -v to preview what grep's invert flag would keep.

BRE and ERE in one minute

BRE is what plain grep and plain sed use: write \+, \?, \|, \(\) and \{\} to get operator behavior. ERE is what grep -E and sed -E use, where those same symbols work unescaped, much like the regex you know from modern languages. Anchors, character classes, dot and star behave identically in both. The tester translates whichever flavor you choose so the highlighting reflects what the real tools would match, and common POSIX classes like [[:digit:]] are supported.

Commands, written for you

Below the results you get three ready commands built from your exact pattern and flags: a grep line, a sed print-matching-lines line, and a sed substitution with a REPLACEMENT placeholder. Slashes inside your pattern are escaped automatically for the sed forms.

Patterns get tested against real files eventually. The Find Command Composer can feed a whole directory tree into grep, and if the search runs on a remote box, set up painless access with the SSH Config Generator.

More tools from CommandLinux

Grep/Sed Regex Tester Find Command Composer SSH Config Generator Crontab Decoder Systemd Service Generator Chmod Permissions Calculator Tar Command Builder IP Subnet Calculator Command Line Quiz Bash Script Boilerplate Generator

Willie has over 15 years of experience in Linux system administration and DevOps. After managing infrastructure for startups and enterprises alike, he founded Command Linux to share the practical knowledge he wished he had when starting out. He oversees content strategy and contributes guides on server management, automation, and security.