Solved

Replace string with wildcard in perl

Posted on 2010-11-26
9
707 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: 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

Technology Partners: 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!

Question has a verified solution.

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

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.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…

739 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