
The negative numbering starts with -1 to refer to the capture group closest to the backreference that was defined before the backreference. # use '\g(?P+),(?P=col3),'Īnother useful approach when there are numerous capture groups is to use negative backreferences. The match made with this part of the pattern is remembered for later use, as described in Using groups. The last example includes parentheses, which are used as a memory device. $ echo '123456789abc42az' | grep -E '(.)(.)(.)(.)(.)(.)(.)(.)(.)(.).*\10' 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/.

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