CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: Regular Expressions:
Need some help with regex.



Oct 28, 2008, 6:13 PM

Post #1 of 2 (8733 views)
Need some help with regex. Can't Post

I have an array with the following content, a list of URLs.

I'm creating a script that will look in this array, and remove all the self-referencing link, and non-local links for the base URL that I'm looking for.

So if I'm looking for (base URL), I will need to remove from the array,,, and

My problem is in the regular expression to do that, I got it to remove all the non-local links, but now I'm not sure on how to remove the self-referencing links. Can I get some help to complete the regular expression.

Thank you

Here is what I have.


$base =;
for ($counter = 0; $counter <= $#links; $counter++){
if ($links[$counter] =~ m/($base)/){
#do something
} else {
#do something


Feb 26, 2009, 1:25 PM

Post #2 of 2 (8011 views)
Re: [Ennio] Need some help with regex. [In reply to] Can't Post

Hi Ennio,

Maybe something like this?

$base =;  
for ($counter = 0; $counter <= $#links; $counter++){
# Shift parentheses to remember the relative url (if any), not the base.
if ($links[$counter] =~ m|^$base(.*)|){
# Local link.
# $1 is the "remembered" string matched above.
my $rUrl = $1 if $1;
if ( $rUrl and $rUrl =~ m/^index|^default/ ) {
# Self referential link. Throw away.
} else {
# keep

} else {
# Non-local link. Throw away.




Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives