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?
I want to search for anything with @R2_ in its ending and replace it with @R2_leaf
how do i do this in perl?
ASKER
the strings are either @R2_ or @R2_l or @R2_le or @R@_lea, I want to make them all @R2_leaf
ASKER
the substrings are at the end of a much longer string
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
so would the complete command be perl -pi.bak -e 's/\@R[2@]_|?e?a?$/\@R2_le af/g' filename
if end of the strings means end of the lines, then yes
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
what does this mean? I have seen in before while trying various replace methods, before submitting this question.
ASKER
thanks. it worked.
s/\@R2_/\@R2_leaf/
And where is the wildcard?