Solved

pattern writing

Posted on 1998-09-03
2
143 Views
Last Modified: 2010-03-05
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.
0
Comment
Question by:rongz
2 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 50 total points
ID: 1204683
$match = 'name1';

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

0
 
LVL 84

Expert Comment

by:ozo
ID: 1204684
#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

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question