简体   繁体   English

Ruby 脚本,用于匹配 PHP 文件上的双引号并将其替换为单引号

[英]Ruby script to match and replace double quotes to single quotes on PHP files

I'm trying to code a ruby script to replace double quotes to single quotes in PHP files when there's no parsing happening, need some help with the regex seeing that I'm still trying to learn it.我正在尝试编写一个ruby 脚本,以便在没有发生解析的情况下将PHP文件中的双引号替换为单引号,需要一些关于正则表达式的帮助,因为我仍在努力学习它。 Got something like this for string interpolation matching: \\"([^\\$].*?)\\" but it still match patterns with $ in it.有这样的字符串插值匹配: \\"([^\\$].*?)\\"但它仍然匹配包含 $ 的模式。

Example例子

How it's supposed to work它应该如何工作

Before running the script:在运行脚本之前:

// Normal string
$first = "some value";
// With var concatenation:
$second = "first var value is " . $first . "!";
// With var interpolation:
$third = "first var value is $first!";
// Arrays
$arr["fourth"] = $first;

Example after running the script:运行脚本后的示例:

// Normal string
$first = 'some value';
// With var concatenation:
$second = 'first var value is ' . $first . '!';
// With var interpolation:
$third = "first var value is $first!";
// Arrays
$arr['fourth'] = $first;

Any idea of regex I could use to match these scenarios?我可以使用正则表达式来匹配这些场景吗?

You don't need this ".*" because it will match all char.您不需要这个“.*”,因为它将匹配所有字符。
try this:尝试这个:

"([^\$]+)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM