Basic HTML version of Foils prepared March 30 97

Foil 44 The Matching Operator in Regular Expressions - III
\1 $1 $` $& and $' etc.
(Chapter 7 of the Llama Book)

From PERL4 Tutorial for CPS616 Computational Science for Information Age Course CPS616 -- February 1995. by Geoffrey C. Fox


We have defined \1, \2, \3 .. as variables set by parentheses and used internally to a match. These variables are available outside the regular expression operation with conventional PERL names $1 $2 $3 etc. Use latter even in substitution.
In string matched in part by a regular expression, we can identify three parts
  • $` is variable holding part of string BEFORE matched part
  • $& is variable holding part of string matched by regular expression
  • $' is variable holding part of string AFTER matched part
So string is concatenation $` . $& . $'



© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sat Sep 6 1997