Posted over 4 years ago. Visible to the public.

Linux: Using grep with a regular expression

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

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

Difference between basic and extended:

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.

Copy
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.

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Andreas Robecke
Last edit:
about 1 month ago
by Judith Roth
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Andreas Robecke to makandra dev
This website uses short-lived cookies to improve usability.
Accept or learn more