簡體   English   中英

如何在 XML 摘要之間捕獲文本?

[英]How to capture text between XML Summary?

我有單行和多行 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>

在 RegexBuddy 中,如果沒有 /// 和<summary> </summary>標簽,我將如何捕獲其中的文本?

我想出了以下捕獲多行 XML 的摘要:

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

和單個 XML 摘要:

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

但我不知道如何僅捕獲文本。

我將使用什么正則表達式來捕獲文本,以便我可以在替換參考中使用它?

先感謝您。

使用 PCRE 引擎:

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

證明

解釋

--------------------------------------------------------------------------------
  (?:                      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