in reply to Backref in a regex quantifier
use strict; foreach ( "123 123 ", "1 1 ", "45 &45 " ) { print( "\"$_\"\n " ); if ( /^(\d+?) (.\1) / ) { printf( "Match 1 => \"%s\", Match 2 => \"%s\"\n", $1, $2 ); } else { print( "No match\n" ); } }
Outputs:
"123 123 " Match 1 => "123", Match 2 => " 123" "1 1 " No match "45 &45 " Match 1 => "45", Match 2 => "&45"
Update: corrected spelling in sentence.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Backref in a regex quantifier
by Crackers2 (Parson) on Jul 09, 2007 at 13:57 UTC |