Skip to content

Regular expressions

Online tester:

  • regex101 Online regex tester, no posix syntax/flavor
  • regexr
    • Only PCRE & JavaScript flavors are supported

Posix BRE / ERE

Gnu grep:

grep understands three different versions of regular expression syntax: “basic” (BRE), “extended” (ERE) and “perl” (PCRE).

Sed:

POSIX.2 BREs should be supported, but they aren't completely because of performance problems.

Awk:

The awk utility shall make use of the extended regular expression notation (see the Base Definitions volume of POSIX.1‐2017, Section 9.4, Extended Regular Expressions) except that it shall allow the use of C-language conventions for escaping special characters within the EREs, …

Extract Ip-Numbers

grep -o '[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}' file.txt

Greedy wildcards

Insert Line before regexp

sed '/<\/wpt>/{x;s/.*/  <category>Camping Frankr<\/category>/;G;}' /tmp/test.gpx
  • [[:digit:]]

Obfuscate Email Adr

echo "varac@example.org"| sed 's/@/ {at} /'|sed 's/\(.*\)\./\1{dot}/'

Grep inside .tgz

https://stackoverflow.com/questions/13983365/grep-from-tar-gz-without-extracting-faster-one

tar xf jessie_packaging.tgz --to-command \
  "awk '/httpredir/ { print ENVIRON[\"TAR_FILENAME\"]; exit }'"