1

I have a question concerning Perl.

Assume I have the following line in my file:

DoMatchLong ( "ThisIsMyVariable", lThisIsMyVariable);

I want to replace "ThisIsMyVariable" by cp_const_ThisIsMyVariable

So my aim is:

DoMatchLong (  cp_const_ThisIsMyVariable, lThisIsMyVariable);


$count = s/(?<=")\w+(?=")/const_cmd_cp_$&/gx;

leads to DoMatchLong ( "cp_const_ThisIsMyVariable", lThisIsMyVariable);

So what is the correct solution?

1 Answer 1

5
$count = s/"(\w+)"/const_cmd_cp_$1/gx;

Pull the quotes into the match, then use a capturing group to get only the actual text between the quotes, while still replacing them.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much! You answered faster than I understood your solution. I like the possibility of grouping regexpes!
You probably should mark the question as answered if you've tried the solution and it works for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.