Solved

Replace string with wildcard in perl

Posted on 2010-11-26
9
697 Views
Last Modified: 2012-05-10
I have string with various endings; however, they all have a substring in common in toward the end of the string,  @R2_
I want to search for anything with @R2_ in its ending and replace it with @R2_leaf
how do i do this in perl?  
0
Comment
Question by:MichelleLacy
  • 5
  • 4
9 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 34220000
What part of the string is "toward the end of the string"?

s/\@R2_/\@R2_leaf/

And where is the wildcard?
0
 

Author Comment

by:MichelleLacy
ID: 34220007
the strings are either @R2_ or @R2_l or @R2_le or @R@_lea, I want to make them all @R2_leaf
0
 

Author Comment

by:MichelleLacy
ID: 34220008
the substrings are at the end of a much longer string
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 34220013
s/\@R[2@]_l?e?a?$/\@R2_leaf/ for @strings;
0
 

Author Comment

by:MichelleLacy
ID: 34220028
so would the complete command be  perl -pi.bak -e 's/\@R[2@]_|?e?a?$/\@R2_leaf/g' filename
0
 
LVL 84

Expert Comment

by:ozo
ID: 34220059
if end of the strings means end of the lines, then yes
0
 
LVL 84

Assisted Solution

by:ozo
ozo earned 500 total points
ID: 34220063
Except that | should be l
0
 

Author Comment

by:MichelleLacy
ID: 34220081
after typing in the command i get the message "Quantifier follows nothing before HERE mark in regex m/\@R[2@]_|? << HERE e?a?$/ at -e line 1"

what does this mean?  I have seen in before while trying various replace methods, before submitting this question.
0
 

Author Closing Comment

by:MichelleLacy
ID: 34220248
thanks.  it worked.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…

713 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