What flavour of regular expression is grep?

前端 未结 6 1279
花落未央
花落未央 2021-02-03 23:41

I\'m guessing it\'s not a Perl Compatible Regular Expression, since there\'s a special kind of grep which is specifically PCRE. What\'s grep most simil

相关标签:
6条回答
  • 2021-02-04 00:14

    There is no regular grep function in PHP. If you are referring to the ereg family of PHP functions then those are POSIX regular expressions. If you are referring to the Linux grep commandline utility, those are POSIX regular expressions as well. It supports both basic as well as extended POSIX regular expressions.

    0 讨论(0)
  • 2021-02-04 00:14

    POSIX BRE (Basic Regular Expressions)

    You can compare the various flavors here.

    0 讨论(0)
  • 2021-02-04 00:18

    The grep man pages do a pretty thorough job of explaining the flavor of regexp available in grep. man grep is pretty useful.

    0 讨论(0)
  • 2021-02-04 00:19

    Default GNU grep behavior is to use a slightly flavorful variant on POSIX basic regular expressions, with a similarly tweaked species of POSIX extended regular expressions for egrep (usually an alias for grep -E). POSIX ERE is what PHP ereg() uses.

    GNU grep also claims to support grep -P for PCRE, by the way. So no terribly special kind of grep required.

    0 讨论(0)
  • 2021-02-04 00:29

    Grep is an implementation of POSIX regular expressions. There are two types of posix regular expressions -- basic regular expressions and extended regular expressions. In grep, generally you use the -E option to allow extended regular expressions.

    0 讨论(0)
  • 2021-02-04 00:33

    There's a good write-up here. To quote the page, "grep is supposed to use BREs, except that grep -E uses EREs. (GNU grep fits some extensions in where POSIX leaves the behaviour unspecified)."

    In other words, it's a long story. ;)

    0 讨论(0)
提交回复
热议问题