簡體   English   中英

Perl正則表達式說明

[英]Perl regular expression explanation

我有這樣的正則表達式:

 s/<(?:[^>'"]|(['"]).?\1)*>//gs

我不知道這到底是什么意思。

正則表達式看起來旨在從輸入中刪除HTML標記。

它匹配文本開頭<並與結尾> ,含有非> /非引號或引用的字符串(其可以包含> )。 但它似乎有一個錯誤:

.? 說引號可以包含0或1個字符; 它可能是.*? (0個或更多字符)。 並防止回溯做類似的事情. 在某些情況下,奇匹配報價,它需要改變(?: ... )分組是占有欲( >而不是: )。

此工具可以解釋詳細信息: http : //rick.measham.id.au/paste/explain.pl?regex=%3C%28%3F% 3A[^% 3E%27%22]|%28[%27 %22]%29%3F \\ 1%29 *%3E

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  <                        '<'
--------------------------------------------------------------------------------
  (?:                      group, but do not capture (0 or more times
                           (matching the most amount possible)):
--------------------------------------------------------------------------------
    [^>'"]                   any character except: '>', ''', '"'
--------------------------------------------------------------------------------
   |                        OR
--------------------------------------------------------------------------------
    (                        group and capture to \1:
--------------------------------------------------------------------------------
      ['"]                     any character of: ''', '"'
--------------------------------------------------------------------------------
    )                        end of \1
--------------------------------------------------------------------------------
    .?                       any character except \n (optional
                             (matching the most amount possible))
--------------------------------------------------------------------------------
    \1                       what was matched by capture \1
--------------------------------------------------------------------------------
  )*                       end of grouping
--------------------------------------------------------------------------------
  >                        '>'

因此,它嘗試刪除ysth也提到的HTML標簽。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM