Advertisement

12.29.2007 at 08:29AM PST, ID: 23048887 | Points: 250
[x]
Attachment Details

RegEx Memory Variables - Easy example BUT $1 not holding what I expected

Asked by lqwest in Perl Programming Language

Tags:

In the code below the $1 memory variable holds Samua (notice NO l )  instead of Samual? My question is why? I know HOW to fix the problem to get what I want, but want to learn WHY $1 does not hold what I expect.

The output  of the code snippet is:
Starting string $_ is: Samual Adams
$1 is:Samua $2 is:l Adams                           <------ my area of concern
$1 is:Samual $2 is:Adams              

From my book on the subject "The memory holds the part of the string matched by the part of the pattern inside the parenthesis". So inside the first parens I think it would find the entire first name 'Samual'?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
use strict;
$_ = "Samual Adams";
print "Starting string \$_ is: $_\n";
s{(\w+)(\w+)} {\$1 is:$1 \$2 is:$2}xms;       #area of concern
print "$_\n";
$_ = "Samual Adams";
s{(\w+)[ ](\w+)} {\$1 is:$1 \$2 is:$2}xms;
print "$_\n";
[+][-]12.29.2007 at 08:39AM PST, ID: 20548197

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2007 at 11:30AM PST, ID: 20548677

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2007 at 04:16PM PST, ID: 20549488

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2007 at 04:35PM PST, ID: 20549523

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2007 at 05:12PM PST, ID: 20549591

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.29.2007 at 07:10PM PST, ID: 20549770

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2007 at 07:10PM PST, ID: 20549771

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.29.2007 at 07:12PM PST, ID: 20549776

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.30.2007 at 06:29PM PST, ID: 20553087

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]12.30.2007 at 07:54PM PST, ID: 20553264

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]12.30.2007 at 07:57PM PST, ID: 20553265

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628