开发者

regex replace in middle

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜