Regex, getting closer

Regex, getting closer

am 22.10.2006 14:23:21 von nugget1960

This line of code successfully notates internal links with .
What I really want it to do, is to notate the external links.
How do I change the regex to add a notation only a link exists without
"sample.com.au"?

$html_code =~
s{(]*?href="([^""]+\.sample.com.au))([^>]*">.*?/a>)}{$1 $3
}gsi;

Mark

Re: Regex, getting closer

am 23.10.2006 03:34:01 von paduille.4060.mumia.w

On 10/22/2006 07:23 AM, Mark & Ingrid Nugent wrote:
> This line of code successfully notates internal links with .
> What I really want it to do, is to notate the external links.
> How do I change the regex to add a notation only a link exists without
> "sample.com.au"?
>
> $html_code =~
> s{(]*?href="([^""]+\.sample.com.au))([^>]*">.*?/a>)}{$1 $3
> }gsi;
>
> Mark
>
>


This code is untested:

sub not_sample {
if ($_[1] =~ /\.sample\.com\.au$/) {
"$_[0] $_[2]";
} else {
"$_[0] $_[2] ";
}
}

$html_code =~
s{(]*?href="([^""]+\.sample.com.au))([^>]*">.*?/a>)}
{not_sample($1,$2,$3)}gsei;


Notice that I used the /e option to the s/// operator to tell it to
execute perl code to get the replacement string. That perl code is
not_sample($1,$2,$3), and that subroutine does some simple tests on the
URL before returning the replacement string.

Read the documentation: perldoc perlre


--
paduille.4060.mumia.w@earthlink.net