[A complimentary Cc of this posting was sent to
Jim Gibson
<
jgibson@...>], who wrote in article <
020820070913060006%jgibson@...>:
> 1. If you want your match to start at the beginning of your string you
> must anchor the pattern with ^ or \A.
> 2. If you want your grouped item to have more than zero characters,
> then use + instead of * for a repeat quantifier character.
> 3. If there is not a match, then there will be nothing valid in $1.
> Untested:
> if ($a =~ /^([0-9]+)abc\1/)
> {
> print "matched $1 \n";
> }
> else
> {
> print "No match\n";
> }
More anchored is still needed for \1. Like (?<![0-9])\1$.
And if one does not want a fixed string "abc", one needs more
anchoring for the leading (); in this case, one does not need
look-ahead, it is enough to use (?>).
$a = "000abc0000";
if ($a =~ /^((?>[0-9]+)).*(?<![0-9])\1$/)
{
print "matched $1 \n";
}
else
{
print "No match\n";
}
Hope this helps,
Ilya