简体   繁体   English

如何在 XML 摘要之间捕获文本?

[英]How to capture text between XML Summary?

I have single-line and multi-line XML Summary texts, that look like these.我有单行和多行 XML 摘要文本,看起来像这些。

/// <summary> This is a single-line XML comment. </summary> 

/// <summary> This is a multi-line XML comment.
/// These are additional lines with more text.
/// Some more of these text. </summary>

/// <summary> This is another XML text summary with a different
/// format.
/// </summary>

In RegexBuddy, how would I capture the texts within, without the /// and the <summary> </summary> tags?在 RegexBuddy 中,如果没有 /// 和<summary> </summary>标签,我将如何捕获其中的文本?

I came up with the following to capture a multi-line XML summary:我想出了以下捕获多行 XML 的摘要:

  ((\s*(///)\s*((<summary>)?))(.*))+(</summary>)$

and a single XML summary:和单个 XML 摘要:

  \s*///\s*(<summary>).*(</summary>)$

But I've no idea how to capture just the text.但我不知道如何仅捕获文本。

What would be the regular expression I would use, in order to capture just the text, so that I can use it in a replacement reference?我将使用什么正则表达式来捕获文本,以便我可以在替换参考中使用它?

Thank you in advance.先感谢您。

Use the PCRE engine:使用 PCRE 引擎:

(?:^///\s*(?:<summary>)?|</summary>)(*SKIP)(*F)|(?:(?!</?summary>|^///(?!/)\s*).)+

See proof证明

Explanation解释

--------------------------------------------------------------------------------
  (?:                      group, but do not capture:
--------------------------------------------------------------------------------
    ^                        the beginning of the string
--------------------------------------------------------------------------------
    ///                      '///'
--------------------------------------------------------------------------------
    \s*                      whitespace (\n, \r, \t, \f, and " ") (0
                             or more times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
    (?:                      group, but do not capture (optional
                             (matching the most amount possible)):
--------------------------------------------------------------------------------
      <summary>                '<summary>'
--------------------------------------------------------------------------------
    )?                       end of grouping
--------------------------------------------------------------------------------
   |                        OR
--------------------------------------------------------------------------------
    </summary>               '</summary>'
--------------------------------------------------------------------------------
  )                        end of grouping
--------------------------------------------------------------------------------
  (*SKIP)                     'SKIP' verb, skips the match
--------------------------------------------------------------------------------
  (*F)                        'FAIL' verb, triggers fail and backtracking
--------------------------------------------------------------------------------
 |                        OR
--------------------------------------------------------------------------------
  (?:                      group, but do not capture (1 or more times
                           (matching the most amount possible)):
--------------------------------------------------------------------------------
    (?!                      look ahead to see if there is not:
--------------------------------------------------------------------------------
      <                        '<'
--------------------------------------------------------------------------------
      /?                       '/' (optional (matching the most
                               amount possible))
--------------------------------------------------------------------------------
      summary>                 'summary>'
--------------------------------------------------------------------------------
     |                        OR
--------------------------------------------------------------------------------
      ^                        the beginning of the string
--------------------------------------------------------------------------------
      ///                      '///'
--------------------------------------------------------------------------------
      (?!                      look ahead to see if there is not:
--------------------------------------------------------------------------------
        /                        '/'
--------------------------------------------------------------------------------
      )                        end of look-ahead
--------------------------------------------------------------------------------
      \s*                      whitespace (\n, \r, \t, \f, and " ")
                               (0 or more times (matching the most
                               amount possible))
--------------------------------------------------------------------------------
    )                        end of look-ahead
--------------------------------------------------------------------------------
    .                        any character except \n
--------------------------------------------------------------------------------
  )+                       end of grouping

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM