pattern writing

hello,
there is a long string,the content is:

 $str="name1(432)\n
       name2(89)\n
       name3(3423)\n
       name1(21)\n";
the problem is I want to delete some name and its value from  $str and only once searching from end(reverse order).
for example:
 if I specify "name1"(its value not given),the result should be:  $str="name1(432)\n
          name2(89)\n
         name3(3423)\n"
Thanks.
rongzAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
b2piConnect With a Mentor Commented:
$match = 'name1';

$str =~ s/(.*)($match\(\d*\)\s*)(.*?)$/\1\3/s;

0
 
ozoCommented:
#or
$str =~ s/(.*)\b$match\(\d*\)\s*/\1/s;
#but this can leave spaces at the end if name1 is on the last line.
0
All Courses

From novice to tech pro — start learning today.