Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between regex types

I'm reading the GNU find's man page and stumbling upon this switch:

-regextype type
          Changes the regular  expression  syntax  understood  by  -regex  and
          -iregex  tests  which  occur  later on the command line.  Currently-
          implemented types are emacs (this is the default), posix-awk, posix-
          basic, posix-egrep and posix-extended.

What's the difference between those regex syntaxes? I'm more familiar with Ruby's regex, so what type of regex should I use with find?

like image 278
Lamnk Avatar asked Dec 26 '11 22:12

Lamnk


1 Answers

Regular expressions are implemented in many ways. POSIX Extended Expressions know the same metacharacters as POSIX Basic Expressions but with a few additions as you can see on this page.

In some cases one might want to use a certain metacharacter known by one of those implementations and you can use this option to tell find which one you are using. If you only need a more basic expression, posix-basic would be enough.

Also you might just prefer the type of RegEx you are used to and find is able to interpret it correctly.

As fge mentioned, use this site to learn more about the differences between RegEx syntactics.

like image 75
markusschmitz Avatar answered Nov 14 '22 06:11

markusschmitz