説明
<%--((?:<\/?[a-z]+(?=[\s>])(?:[^>=]|=(?:'[^']*'|"[^"]*"|[^'"\s]*))*\s?\/?>|[^<])*?)--%>
この正規表現は、次の操作を行います:
- は
<%--
と--%>
タグ
- 内括弧コメントの内容全体を節約見つけますグループ1をキャプチャするコメントタグ は難しいHTMLのパターンマッチング
例
ライブデモ
https://regex101.com/r/fH2xU5/3
サンプルテキストを作ることが困難エッジケースを回避
<span><a onmouseover=' if (3 > a) { var string=" <img src=NotTheDroidYouAreLookingFor.jpg>; "; } ' href="link.html">This is a droid I'm looking for: <img src=DesiredDroids.png></a>
</span>
<%--
<img onmouseover=' if (3 > a) { var string=" --%> <img src=NotTheDroidYouAreLookingFor.jpg>; "; } ' src="/x.gif" alt='x.gif'>
<input type="text" name="x" value="y">
--%>
No start comment tag
<img src="/x.gif" alt='x.gif'>
<input type="text" name="x" value="y">
--%>
<%--
<img src="/x.gif" alt='x.gif'>
<input type="text" name="x" value="y">
--%>
必要なテキストでどのような機能
サンプルと一致し
MATCH 1
1. [196-369] `
<img onmouseover=' if (3 > a) { var string=" --%> <img src=NotTheDroidYouAreLookingFor.jpg>; "; } ' src="/x.gif" alt='x.gif'>
<input type="text" name="x" value="y">
`
MATCH 2
1. [481-557] `
<img src="/x.gif" alt='x.gif'>
<input type="text" name="x" value="y">
説明
NODE EXPLANATION
----------------------------------------------------------------------
<%-- '<%--'
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the least amount
possible)):
----------------------------------------------------------------------
< '<'
----------------------------------------------------------------------
\/? '/' (optional (matching the most
amount possible))
----------------------------------------------------------------------
[a-z]+ any character of: 'a' to 'z' (1 or
more times (matching the most amount
possible))
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
[\s>] any character of: whitespace (\n,
\r, \t, \f, and " "), '>'
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?: group, but do not capture (0 or more
times (matching the most amount
possible)):
----------------------------------------------------------------------
[^>=] any character except: '>', '='
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
= '='
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
' '\''
----------------------------------------------------------------------
[^']* any character except: ''' (0 or
more times (matching the most
amount possible))
----------------------------------------------------------------------
' '\''
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
[^"]* any character except: '"' (0 or
more times (matching the most
amount possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[^'"\s]* any character except: ''', '"',
whitespace (\n, \r, \t, \f, and "
") (0 or more times (matching the
most amount possible))
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
)* end of grouping
----------------------------------------------------------------------
\s? whitespace (\n, \r, \t, \f, and " ")
(optional (matching the most amount
possible))
----------------------------------------------------------------------
\/? '/' (optional (matching the most
amount possible))
----------------------------------------------------------------------
> '>'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[^<] any character except: '<'
----------------------------------------------------------------------
)*? end of grouping
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
--%> '--%>'
----------------------------------------------------------------------
他のテキストつまり、それらは違う何か他の言葉で...あなたがそれらを維持したいように特別ですあなたはマッチしたくないですか? –
私は正規表現マッチマルチラインを使用したいと私は問題を使用して?:?!パターンマッチ、私はそれをfiguareする方法を知りません。 :< –