簡體   English   中英

Ruby 腳本,用於匹配 PHP 文件上的雙引號並將其替換為單引號

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

我正在嘗試編寫一個ruby 腳本,以便在沒有發生解析的情況下將PHP文件中的雙引號替換為單引號,需要一些關於正則表達式的幫助,因為我仍在努力學習它。 有這樣的字符串插值匹配: \\"([^\\$].*?)\\"但它仍然匹配包含 $ 的模式。

例子

它應該如何工作

在運行腳本之前:

// 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;

運行腳本后的示例:

// 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;

我可以使用正則表達式來匹配這些場景嗎?

您不需要這個“.*”,因為它將匹配所有字符。
嘗試這個:

"([^\$]+)"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM