Regular expressions are a core skill for any half decent programmer.
I use them extensively in languages from Python and Perl to Java/Scala/Groovy and even in shell scripts in Bash for grep, sed & awk.
- Online Regex Testing
- PCRE vs BRE vs ERE
- BRE - Basic Regular Expression
- ERE - Extended Regular Expressions
- Core Reading
- Library of Regex in Perl
- Library of Regex in Python
- Library of Regex in Bash
- Examples of Real-world Regex Used Extensively
Test your sed regex here:
The gold standard from Perl which most popular languages aspire to
GNU grep has a grep -P
switch to use PCRE but beware it's not portable. It won't work on BSD based systems like macOS.
On Mac you can install coreutils to get the better GNU Grep
brew install coreutils
but then you'll have to use the ggrep
command instead.
Your shell scripts will have to figure our if they're on Mac and override the grep command (examples in DevOps-Bash-tools repo).
This is the neutered regex that old grep uses.
Slightly better than BRE but still weak & awkward compared to PCRE.
Don't support back references.
Grep on most systems can support EREs via the grep -E
switch.
Awk also uses EREs.
PCRE regex:
PCRE regex:
BRE / ERE Regex:
PCRE regex - see especially anonymize.py / anonymize.pl in these repos among many other scripts: