Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find command regextype difference between 'posix-extended' and 'posix-egrep'

Tags:

regex

grep

shell

sh

The title really says it all. Can anyone point me to where I could find descriptions of the different regex types available to the find command. I'm able to find a list of them but no explanations or comparisons. In particular, what could the difference be between 'posix-egrep' and 'posix-extended,' since egrep is a tool for regex matching according to the extended set?

like image 943
kegepet Avatar asked Feb 24 '18 21:02

kegepet


People also ask

What is Posix extended regular expression?

10 ' posix-extended ' regular expression syntax. The character ' . ' matches any single character except the null character. ' + ' indicates that the regular expression should match one or more occurrences of the previous atom or regexp.

What is the difference between basic and extended regular expression?

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

Can you use regex with find?

Regular expressions (shortened as regex) are powerful tools described by character sequences that specify a search pattern. This is why their use together with find yields a more refined search with a more reduced command.

Which symbols are used in extended grep in Unix?

grep extended regex (search multiple words) For example to search words abc, fgh, xyz, mno and jkl, use the search pattern "abc|fgh|xyz|mno|jkl".


1 Answers

Let me guide through you how you should use linux's documentation to self-answer questions like this by showing you how exactly I locate information.

  1. I run man find to see some basic information of regular expression type by searching the keyword, regular, then I see this:

-regextype type

Changes the regular expression syntax understood by -regex and -iregex tests which occur later on the command line. To see which regular expression types are known, use -regextype help. The Texinfo documentation (see SEE ALSO) explains the meaning of and differences between the various types of regular expression.

Assuming this is what you are looking for, the doc says it's in Texinfo, so I do the next step;

  1. run info find. Then search regextype to locate the correct section for it. Then I reached:

'--regextype'

This option changes the regular expression syntax and behaviour used by the '--regex' option. *note Regular Expressions:: for more information on the regular expression dialects understood by GNU findutils.

It asks to refer to a further documentation named note Regular Expressions, which you can go to there by hitting enter when cursor's on it.

  1. Hooray!
  • Menu:

  • findutils-default regular expression syntax::

  • awk regular expression syntax::

  • egrep 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::

The last two items are exactly what you are asking. Read both of them, and then you can find out that the system already has the proper answers for you.

like image 154
Jason Hu Avatar answered Sep 29 '22 18:09

Jason Hu