Link to home
Start Free TrialLog in
Avatar of MichelleLacy
MichelleLacy

asked on

Replace string with wildcard in perl

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?  
Avatar of ozo
ozo
Flag of United States of America image

What part of the string is "toward the end of the string"?

s/\@R2_/\@R2_leaf/

And where is the wildcard?
Avatar of MichelleLacy
MichelleLacy

ASKER

the strings are either @R2_ or @R2_l or @R2_le or @R@_lea, I want to make them all @R2_leaf
the substrings are at the end of a much longer string
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
so would the complete command be  perl -pi.bak -e 's/\@R[2@]_|?e?a?$/\@R2_leaf/g' filename
if end of the strings means end of the lines, then yes
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
thanks.  it worked.