Kevin Zembower wrote:
> 
> I'm still having trouble with the regex expression. I've pasted in
> the files and program at the end, for reference.
> 
> In your message, you said:
>     my %hash = ( abstract => '', author => '', endtitle => '' );
>     $hash{ lc $2 } = $3
>         while $query =~ 
> /QF(\d+)=[^&]*\b(abstract|author|endtitle)\b(?=.*?&QI\1=([^&]*))/ig;
> 
> My interpretation of the match statement is:
> Match the letters 'QF' then one or more digits. Capture the digits in \1
> Match anything, or nothing, as long as it's not '&', then look for the
> start of a word, followed by one of the words 'abstract', 'author' or
> 'endtitle' followed by the end of a word. Capture that in the \2 or $2
> variable.

Correct so far.


> Here's where I have a problem: I don't understand the '(' (start the
> third group?) followed by the '?'.

The (?=pattern) is a zero-width positive look-ahead assertion.  It does
not capture to a numeric variable and it does not affect the position of
the next match.  The reason I used it is suppose that you had a string
like:

&QF0=something&QF1=something&QI0=something&QI1=something&

With the zero-width positive look-ahead assertion you would match both 0
and 1 but without it you would only match 0.


> I'll skip up to the 'QI' for now
> Match the letters "QI" followed by the digits captured in \1, then an
> equals sign, then anything or nothing, as long as it's not '&', and
> capture that in the \4 or $4 variable.

No, in the $3 variable.


> I tried to rewrite this statement as:
>    my %hash = (abstract =>'', author =>'', endtitle =>'');
>    $hash{lc $2}=$3 while $query =~ \
>       /QF(\d+)=[^&]*\b(abstract|author|endtitle)\b.*?&QI\1=([^&]*)/ig;
> 
> Which I think means:
> Match the letters 'QF' then one or more digits. Capture the digits in \1
> Match anything, or nothing, as long as it's not '&', then look for the
> start of a word, followed by one of the words 'abstract', 'author' or
> 'endtitle' followed by the end of a word. Capture that in the \2 or $2
> variable.
> Match anything, but as little as possible (".*?"), up to '&QI' then the
> same digits as before, then
> then anything or nothing, as long as it's not '&', and capture that in
> the \3 or $3 variable.
> 
> However, this still isn't matching anything, as the output of the program
> with the data file 'v' below shows.

That is because you have a '\' character between '=~' and the match
operator.  Remove that and it should work.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to