One thing at a time all the time!

Welcome to Rocteur
Friday, April 26 2024 @ 11:44 PM CEST

How do you verify if a regexp has matched something ?

Using the previous example:

my $snippet;
if ( $string =~ /\w\["([^"]+)",/ ) {
$snippet = $1;
}

Or:

$string =~ /\w\["([^"]+)",/ and my $snippet = $1;

Or:

my ( $snippet ) = $string =~ /\w\["([^"]+)",/;

* John W. Krahn

FAQ Manager » Perl » How do you verify if a regexp has matched something ?