c#搜索-替换到php文件


C# search-replace into php file

我是c#的初学者。我试图使一个小工具的搜索& quot;替换成php文件我有这样的输入:

$of_options[] = array(  "name"      => "General Settings",
                         ,"std"   => "General Settings",
                         ,"test"   => "test",
                );          

我想要这个输出:

$of_options[] = array(  'name'      =>__( 'General Settings','$world'),
                         ,"std"   => "General Settings",
                         ,"test"   => "test",
                );      

这是我的尝试:

private string ReplaceBackgroundDirection(string Source)
{   
    return Source.Replace("'"", "'").Replace("=>","=>__(") + ",'$world'),";
}

在正则表达式中使用向后查找和向前查找,您可以在三个部分中实现替换:

        string orig = "'"$of_options[] = array(  '"name'"      => '"General Settings'", ,'"std'"   => '"General Settings'", ,'"test'"   => '"test'", ); '"";
        string output = Regex.Replace(orig,
                                        @"(?<=array'(['s]*)""name""", 
                                        "'name'");
        output = Regex.Replace(output, 
                                  @"(?<='name'['s]*'=>)['s]*""", 
                                  "__( '");
        output = Regex.Replace(output, 
                                  @"(?<='name'['s]*'=>__'([''w's]+)'""+(?=',)", 
                                  "','$world')");