I have a regex which extratcs the name from it.
The code is given below:
Now, if I want to extract the name, like this :
Problem:
Now, I'd like to match the earlier, and get the extracted data ("Shane" here in our example) by a designated name, not a number set by the regex.
Eg.:
^Hello, (?{surname}\w+) \s*!$
then I'll have a way to get the extracted data into $surname or maybe there is a way to do something like this:
Regex.match() is the sub routine name given by me(dont confuse with any existing in built module in Perl).
It is this sub routine which has the functionality of matching the regex and returning the extracted data in the parameter surname.
Any help is highly appreciated.
Thanks.
Regards,
Sakshi
The code is given below:
Code:
# Extract some parts from regex
$input = "Hello, Shane !";
$pattern = "^Hello, \\w+\\s*!\$";
if($input =~ /$pattern/) {
print "\nThe input matches the pattern The dollar variables are\n";
print " \nONE == $1";
print "\n";
}
The input matches the pattern The dollar variables are
ONE == Shane
Problem:
Now, I'd like to match the earlier, and get the extracted data ("Shane" here in our example) by a designated name, not a number set by the regex.
Eg.:
^Hello, (?{surname}\w+) \s*!$
then I'll have a way to get the extracted data into $surname or maybe there is a way to do something like this:
Code:
my $input = "Hello, Shane !";
my $regex = '^Hello, (?{surname}\w+)\s*!$'
my %match = Regex.match($regex, $input);
$match{"surname"} == "Shane"; # true
It is this sub routine which has the functionality of matching the regex and returning the extracted data in the parameter surname.
Any help is highly appreciated.
Thanks.
Regards,
Sakshi
Comment