Read more

Linux: Using grep with a regular expression

Andreas Robecke
December 06, 2016Software engineer

You can use three different versions of the regular expression syntax in grep:

  • basic: -G
  • extended: -E(POSIX)
  • perl: -P (PCRE)
Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

Difference between basic and extended Show archive.org snapshot :

In basic regular expressions the meta-characters '?', '+', '{', '|', '(', and ')' loose their special meaning; instead use the backslashed versions '?', '+', '{', '|', '(', and ')'.

Difference between extended (POSIX) and perl (PCRE): E.g. \d is not supported in POSIX.

This grep command searches for the same pattern in different regular expression versions.

grep -G "[0-9]\{4\}ms" production.log
grep -E "[0-9]{4}ms" production.log
grep -P "\d{4}ms" production.log

As a Ruby dev, you may want to choose the Perl syntax, because it's more similar to how Ruby's regular expressions work than the others.

Posted by Andreas Robecke to makandra dev (2016-12-06 22:10)