Solved

Replace string with wildcard in perl

Posted on 2010-11-26
9
659 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
  • 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
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 34220013
s/\@R[2@]_l?e?a?$/\@R2_leaf/ for @strings;
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
This video discusses moving either the default database or any database to a new volume.

757 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now