Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences between regular expression syntaxes for different tools? [closed]

Tags:

regex

grep

sed

awk

gnu

Different tools implement regular expressions differently. For example to match "foo" or "bar":

printf "%s\n" foo bar baz food | grep -o '\<\(fo\+\|bar\)\>'
printf "%s\n" foo bar baz food | awk '/\<(fo+|bar)\>/'
printf "%s\n" foo bar baz food | sed -n '/\<\(fo\+\|bar\)\>/p'
printf "%s\n" foo bar baz food | sed -nr '/\<(fo+|bar)\>/p'

Where are these differences documented?

like image 426
glenn jackman Avatar asked Mar 18 '14 22:03

glenn jackman


People also ask

What are different types of regular expression?

There are also two types of regular expressions: the "Basic" regular expression, and the "extended" regular expression.

What is the difference between basic regular expressions and extended regular expressions?

5.2 Basic (BRE) and extended (ERE) regular expression In GNU sed , the only difference between basic and extended regular expressions is in the behavior of a few special characters: ' ? ', ' + ', parentheses, braces (' {} '), and ' | '.

What is the syntax to define a regular expression?

Writing a regular expression pattern. A regular expression pattern is composed of simple characters, such as /abc/ , or a combination of simple and special characters, such as /ab*c/ or /Chapter (\d+)\.\d*/ . The last example includes parentheses, which are used as a memory device.

What are different types of regular expression in Python?

Python offers two different primitive operations based on regular expressions: match checks for a match only at the beginning of the string, while search checks for a match anywhere in the string (this is what Perl does by default).


1 Answers

Score! I'm so happy to have found this page:
https://www.gnu.org/software/gnulib/manual/html_node/Regular-expression-syntaxes.html

14.8 Regular expression syntaxes

Gnulib supports many different types of regular expressions; although the underlying features are the same or identical, the syntax used varies. The descriptions given here for the different types are generated automatically.

  • awk regular expression syntax
  • egrep regular expression syntax
  • ed regular expression syntax
  • emacs regular expression syntax
  • gnu-awk regular expression syntax
  • grep regular expression syntax
  • posix-awk regular expression syntax
  • posix-basic regular expression syntax
  • posix-egrep regular expression syntax
  • posix-extended regular expression syntax
  • posix-minimal-basic regular expression syntax
  • sed regular expression syntax
like image 118
glenn jackman Avatar answered Oct 02 '22 18:10

glenn jackman