无法获得第二行正则表达式的第5行,并始终在序列号后面

时间:2017-10-22 12:18:40

标签: regex notepad++ regex-negation

我正在尝试使用Regex来获取始终等于5的序列号,并始终包含单词SerialNumber

我有以下内容:

   <authentication mode="Forms">
  <forms loginUrl="~/Login" timeout="2880"></forms>
</authentication>

文字如下:

       [Authorize]
    [AttributeRouting.Web.Mvc.GET("Admin")]
    public ActionResult Admin()
    {

        return View();
    }

为什么这不起作用?

enter image description here

2 个答案:

答案 0 :(得分:3)

试试这个正则表达式:

SerialNumber\s*\K\S*

Click for Demo

<强>解释

  • SerialNumber\s* - 匹配文字SerialNumber,后跟0个以上的空格
  • \K - 忘记目前为止匹配的所有内容
  • \S* - 匹配任何不是空白字符的字符的出现次数。

答案 1 :(得分:1)

使用正面lookbehind的正则表达式:

(?<=SerialNumber\n)(\S+)

Regex101.com