Solved

pattern writing

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Filtering a file to table 9 102
Perl string replace for refred url 9 70
what are these modules in perl script 4 104
Perl Versus AWK? 7 67
On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
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.…
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…

685 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