Solved

pattern writing

Posted on 1998-09-03
2
136 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now