什么是正则表达式,它将在我的匹配后添加一些字符.价值

本文关键字:添加 价值 字符 我的 正则表达式 什么 | 更新日期: 2023-09-27 18:23:36

我在linq表达式中有一段代码,问题是如果我使用match。值,它只打印匹配字符,我想要的是打印匹配字符加上30个字符。你可以在评论标签中看到我的一些方法,因为我有条件在哪里,所以什么都不打印!regexis.match

foreach (var errorModel in from Match match in Regex.Matches(line, @"<(?!/)[^<]*?>'s+")
                                       where !Regex.IsMatch(line, @"<.+?/>")
                                       select new ErrorModel
                                       {
                                           LineNumber = lineno[0],
                                           ErrorMessage = "Check space after opening tag.",
                                           Text = match.Value
                                           //Text = Regex.Match(line, @"'D{10,30}<(?!/)[^<]*?>'s+").Value
                                       })
            {
                ErrorList.Add(errorModel);
            }

什么是正则表达式,它将在我的匹配后添加一些字符.价值

可以进行文本检索:

Text = line.Substring(match.Index, Math.Min(line.Length - match.Index, 30))

你需要查看原始行,因为你不可能(容易)有重叠的匹配。

哪里的情况可疑。你真的想跳过所有包含结束标记的行吗?

正则表达式:怎么样

<[^<>/]*>'s+.{0,30}

它与您的标签匹配任何空格和最多30个其他字符。应该不需要where !Regex.IsMatch(line, @"<.+?/>")