Perl Tutorials -Part 63- Subpatterns: 2

Posted on June 3, 2010. Filed under: Perl Tutorials |


#perl pattern matching example, reference sub-pattern inside regex \n
$_ = 'The room was full of foxes and fins.';
#\1 reference the sub-pattern captured by 1st ()
/([a-z])oxes and \1ins\./;
#the whole matched pattern
print $&;
print "\n";
#the matched sub-pattern by 1st ()
print $1;

Output:
1
2
foxes and fins.
f
Advertisements

Make a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

%d bloggers like this: