Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 775
  • Last Modified:

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?  
0
MichelleLacy
Asked:
MichelleLacy
  • 5
  • 4
2 Solutions
 
ozoCommented:
What part of the string is "toward the end of the string"?

s/\@R2_/\@R2_leaf/

And where is the wildcard?
0
 
MichelleLacyAuthor Commented:
the strings are either @R2_ or @R2_l or @R2_le or @R@_lea, I want to make them all @R2_leaf
0
 
MichelleLacyAuthor Commented:
the substrings are at the end of a much longer string
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
ozoCommented:
s/\@R[2@]_l?e?a?$/\@R2_leaf/ for @strings;
0
 
MichelleLacyAuthor Commented:
so would the complete command be  perl -pi.bak -e 's/\@R[2@]_|?e?a?$/\@R2_leaf/g' filename
0
 
ozoCommented:
if end of the strings means end of the lines, then yes
0
 
ozoCommented:
Except that | should be l
0
 
MichelleLacyAuthor Commented:
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
 
MichelleLacyAuthor Commented:
thanks.  it worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now