Solved

Replace string with wildcard in perl

Posted on 2010-11-26
9
721 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
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

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…
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…
Six Sigma Control Plans

632 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