

The last example includes parentheses, which are used as a memory device. The negative numbering starts with -1 to refer to the capture group closest to the backreference that was defined before the backreference. A regular expression pattern is composed of simple characters, such as /abc/, or a combination of simple and special characters, such as /abc/ or /Chapter (\d+)\.\d/. # use '\g(?P+),(?P=col3),'Īnother useful approach when there are numerous capture groups is to use negative backreferences.


Backreferences greater than \9 # no match as '\10' will be treated as '\1' and '0'.Backslash sequences inside character class # \w here matches \ and w.Character class metacharacters $ echo 'int a' | grep ''.# line anchors have to be always escaped to match literally Escaping metacharacters $ echo 'a^2 + b^2 - C*3' | grep 'b^2'.This section lists some of the them, along with examples. There are several subtle differences between PCRE and BRE/ERE for the same feature. The example_files directory has all the files used in the examples.
#REGULAR EXPRESSION GREP EXAMPLES MANUAL#
See man pcrepattern or online manual for complete details. Only some of the commonly used features are presented in this chapter. PCRE is handy when you need advanced features like lookarounds, non-greedy quantifiers, possessive quantifiers, unicode character sets, subexpression calls and so on. PCRE is mostly similar, but not exactly the same as regular expressions present in the Perl programming language. The -P option will help you use Perl Compatible Regular Expressions (PCRE) instead of BRE/ERE.
