Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

Perl Regular Expression To replace value in text of variable?

Avatar of KGNickl
KGNicklFlag for United States of America asked on
PerlRegular Expressions
3 Comments1 Solution319 ViewsLast Modified:
See the code below. Basically have a file name, a search value, and a replace value. Everything works, but I don't know regular expressions and how to write one where I have the questions marks that will replace take $file and replace the $search_value within it (if found) with the $replace_value.

Not sure if this can be done in one line w/ a regular expression or if there is another easier way? Thanks! Let me know if anything needs clarification.
my $file = "Test_12354a-bc.doc";
    my $search_value = "12354a";
    my $replace_value = "replaced";
        if($search_value =~ /\b$file\b/){
            #True, replace $search_value found in $file with the $replace_value
            $file = ?????;
            #$file should now be equal to "Test_replaced-bc.doc"
            #False, do nothing
Avatar of jeromee
jeromeeFlag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answers