Visual Studio正则表达式-多行检测 [英] Visual Studio Regular Expression - Multi line detection

查看:122
本文介绍了Visual Studio正则表达式-多行检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下代码中,我想在< Returns>中替换"ReplacedText". xml注释的新文本"部分.


///< summary>
///
///</summary>
///< param name ="x"></param>
///< param name ="y"></param>
///< returns>
///ReplacedText
///</returns>
int Foo1(int x,int y)
{
返回0;
}

///< summary>
///
///</summary>
///< param name ="x"></param>
///< param name ="y"></param>
///< returns>
///ReplacedText
///</returns>
浮点型Foo1(int x,int y)
{
返回0.0F;
}

我在VS的查找/替换"对话框中使用的正则表达式为
///\< returns \> [.\ n] * \</returns \>

但这给出了找不到搜索到的字符串的错误.

您能在我的正则表达式中识别出错误还是建议其他正则表达式吗?

谢谢

fadi

In the following code I want to replace "ReplacedText" in the <Returns> sections of the xml comments to "NewText".


/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns>
/// ReplacedText
/// </returns>
int Foo1(int x, int y)
{
return 0;
}

/// <summary>
///
/// </summary>
/// <param name="x"></param>
/// <param name="y"></param>
/// <returns>
/// ReplacedText
/// </returns>
float Foo1(int x, int y)
{
return 0.0F;
}

The regular expression I used in the Find/Replace dialogbox of VS is
/// \<returns\>[.\n ]*\</returns\>

But this gives the error that searched string is not found.

Can you identify the mistake in my regular expression or suggest a different regular expression?

Thank you

fadi

推荐答案

尝试以下代码:
Try this code:
public static Regex regex = new Regex(
      "\\<returns\\>([^\\<]*)\\</returns\\>",
    RegexOptions.IgnoreCase
    | RegexOptions.Singleline
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );


获得Expresso的副本-它是免费的,确实有帮助!


Get a copy of Expresso - it is free and really helps!


这篇关于Visual Studio正则表达式-多行检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆