views:

76

answers:

1

Hello 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?

Thank you for any help. Best regards Menne

+4  A: 
$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.

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