Home: Perl Programming Help: Regular Expressions:
Match the last but one pattern in a given string



perlwatcher
User

Nov 13, 2009, 1:21 AM


Views: 6045
Match the last but one pattern in a given string

 

my $str = "I am in Hyderabad where Hyderabad is in Andhra Pradesh with Hyderabad being the capital";


My question here is ... how do I match the last "Hyderabad" in the above given string?

Thanks in advance,

Arun


FishMonger
Veteran / Moderator

Nov 13, 2009, 5:14 AM


Views: 6037
Re: [perlwatcher] Match the last but one pattern in a given string

/.*(Hyderabad)/


ichi
User

Nov 13, 2009, 6:58 AM


Views: 6035
Re: [perlwatcher] Match the last but one pattern in a given string


In Reply To

my $str = "I am in Hyderabad where Hyderabad is in Andhra Pradesh with Hyderabad being the capital";


My question here is ... how do I match the last "Hyderabad" in the above given string?

Thanks in advance,

Arun


i don't see any connection here. is "Hyderabad" a constant string? after the last "Hyderabad" is found, then what is the final output?