鉴于$displayHeight = "800";
,用int值y_res
替换800
上的任何数字。C#正则表达式替换意外行为
resultString = Regex.Replace(
im_cfg_contents,
@"\$displayHeight[\s]*=[\s]*""(.*)"";",
Convert.ToString(y_res));
在Python中,我会使用re.sub,它会工作。在.NET中,它将替换整个行,而不是匹配的组。
什么是快速修复?
我同意,这将工作,但该死的这是丑陋的。 – 2009-01-22 15:18:24