Regular Expression Special Variables in Perl


There are various Regular Expression Special Variables in Perl. We have listed them in different below in tabular form −

$digitContains the text matched by the corresponding set of parentheses in the last pattern matched. For example, $1 matches whatever was contained in the first set of parentheses in the previous regular expression.
$&The string matched by the last successful pattern match.
$MATCH
$`The string preceding whatever was matched by the last successful pattern match.
$PREMATCH
$'The string following whatever was matched by the last successful pattern match.
$POSTMATCH
$+The last bracket matched by the last search pattern. This is useful if you don't know which of a set of alternative patterns was matched. For example : /Version: (.*)|Revision: (.*)/ && ($rev = $+);

Updated on: 29-Nov-2019

483 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements