简体   繁体   中英

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. 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:

"([^\$]+)"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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