开发者

regex replace in middle

开发者 https://www.devze.com 2023-01-18 12:05 出处:网络
I tr开发者_JAVA百科ying to replace string \"Resources.AppResource.Info;\" like this \"Switch(\"Info\");\"Is this possible with regex? Is this C#? If it is, then this would work:

I tr开发者_JAVA百科ying to replace string "Resources.AppResource.Info;" like this "Switch("Info");" Is this possible with regex?


Is this C#? If it is, then this would work:

Regex.Replace("Resources.AppResource.Info;", @"Resources\.AppResource\.(\w+);", @"Switch(""$1"")")


You should include the programming language you are working with. And I'm guessing its C#.

string info = System.Text.RegularExpressions.Regex.Replace("Resources.AppResource.Info;", @"\w+\.\w+\.(\w+);", "Switch($1);");


Your question is confusing, a code example would really help, with input and expected output. How does the middle of the string help?

If I understand right you probably want a substitution of one string for another.

Here's some sed, something similar would work for vi and perl

s/Resources\.AppResource\.Info/Switch\("Info"\)\;/

This would work in ruby

app_string.gsub("Resources.AppResource.Info;",
                'Switch("Info")';
0

精彩评论

暂无评论...
验证码 换一张
取 消