Where can I test Bash POSIX ERE patterns interactively?
Asked by
MellowPine42
I'm looking for an online regex playground similar to Regex101, but specifically for the POSIX Extended Regular Expressions used by Bash's =~ operator. Ideally, it should let me enter a pattern and test it against sample strings while accurately reflecting Bash behavior.
Answers
POSIX ERE is also used by tools such as grep -E, egrep, awk, sed -E, and several database regex operators. A playground aimed at any of those tools can be useful, but check whether it uses the same implementation and whether it reproduces Bash quoting and word-splitting behavior.
Reply to this answer
Bashโs =~ operator uses the systemโs POSIX ERE implementation through regcomp. That means behavior can vary slightly between systems, such as glibc and musl. A Bash shell playground like JDoodle can be useful because it tests the expression in an actual Bash script, including Bashโs parsing rules. Remember that spaces in the regex may need to be escaped or quoted.
Reply to this answer
Regex101 now includes an ERE-compatible flavor through its Boost option, so it may work for many tests. For the most reliable result, run the final pattern in Bash itself, since the shell parses the right-hand side before the regex engine sees it.
Reply to this answer
Most online testers default to PCRE, which supports features that POSIX ERE does not. For example, use [0-9] or [[:digit:]] instead of d, and avoid non-capturing groups, lazy quantifiers, lookarounds, named groups, and similar PCRE extensions. Search for testers that specifically advertise POSIX ERE support; rsyslogโs regex tester and RegexTester are possible options, though their exact behavior should be verified.
Reply to this answer
Add your answer
Answers are reviewed before publication.
AmberCactus31: PCRE is broadly more feature-rich, but treating it as a perfect substitute can be misleading. A pattern that works in PCRE may still rely on syntax or matching behavior unavailable in POSIX ERE.