我有一个关于Perl的问题.
假设我的文件中有以下行:
DoMatchLong ( "ThisIsMyVariable", lThisIsMyVariable);
Run Code Online (Sandbox Code Playgroud)
我想用cp_const_ThisIsMyVariable替换"ThisIsMyVariable"
所以我的目标是:
DoMatchLong ( cp_const_ThisIsMyVariable, lThisIsMyVariable);
$count = s/(?<=")\w+(?=")/const_cmd_cp_$&/gx;
Run Code Online (Sandbox Code Playgroud)
导致DoMatchLong ( "cp_const_ThisIsMyVariable", lThisIsMyVariable);
那么正确的解决方案是什么?
$count = s/"(\w+)"/const_cmd_cp_$1/gx;
Run Code Online (Sandbox Code Playgroud)
将引号拉入匹配,然后使用捕获组仅获取引号之间的实际文本,同时仍然替换它们.