[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl-AnyPerl] Regular Expression Problem



[oops, want to send back to the list as well]

Arved suggested:
> 
> $text =~ s/See\salso\s(.+)\./&new_refs($1).'.'/ge;

This will not work if you have another sentence following the "See also" on
the same line, because Arved used greedy matching.

Chris suggested:
> 
>    s{$start(.+?)\.}
>     {$start .
>         join("; ", map {qq'$prog$_">$_</A>'} split(/; */, $1)) . "."
>     }eg;

Chris's solution avoids that problem, but uses the inefficient non-greedy
matching within capturing parens.


A more efficient regex would use a negated character class with greedy
matching, as in:

s/See also ([^.]+)\./ whatever /eg;


Ronald
Campaign to Stamp Out Needless Use of Non-Greedy Matching
:)

==== Want to unsubscribe from this list?
==== Send mail with body "unsubscribe" to macperl-anyperl-request@macperl.org