Home : General : Perl Programming :

General: Perl Programming: Re: [Andy] Replace digit at the end of a string?: Edit Log

Here is the list of edits for this post
Re: [Andy] Replace digit at the end of a string?
Hey Andy, I take it all the values of $_ will contain "Universities Worldwide Search ", right?

Assuming that, if all you want to do is get the name of the country without that string and drop any possible numbers after it and the two possible extensions (.htm and .html), then this expression should do the trick:

my $string = 'Universities Worldwide Search Argentina2.htm';
$string =~ m/Universities Worldwide Search ([^0-9]*)\d*\.html?$/;
print $1;

Basically: match the part of the string following "...Search " which does not contain numbers, followed by zero or more numbers, followed by ".htm" followed by zero or one "l" and start matching at the end of the string.

Let me know if that works for you.

Last edited by:

Crolguvar: Nov 20, 2003, 6:39 AM

Edit Log: