asp.net中的正则表达式用法

时间:2014-02-26 05:57:42

标签: asp.net regex

我想找到这个表达式用法并提供哪种类型的例子支持这个表达式?

ValidationExpression="</?\w+((\s+\w+(\s*=\s*(?:&quot;.*?&quot;|'.*?'|[^'&quot;>\s]+))?)+\s*|\s*)/?>"

1 个答案:

答案 0 :(得分:1)

正则表达式:

</?\w+((\s+\w+(\s*=\s*(?:&quot;.*?&quot;|'.*?'|[^'&quot;>\s]+))?)+\s*|\s*)/?>

NODE                     EXPLANATION
--------------------------------------------------------------------------------
  <                        '<'
--------------------------------------------------------------------------------
  /?                       '/' (optional (matching the most amount
                           possible))
--------------------------------------------------------------------------------
  \w+                      word characters (a-z, A-Z, 0-9, _) (1 or
                           more times (matching the most amount
                           possible))
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    (                        group and capture to \2 (1 or more times
                             (matching the most amount possible)):
--------------------------------------------------------------------------------
      \s+                      whitespace (\n, \r, \t, \f, and " ")
                               (1 or more times (matching the most
                               amount possible))
--------------------------------------------------------------------------------
      \w+                      word characters (a-z, A-Z, 0-9, _) (1
                               or more times (matching the most
                               amount possible))
--------------------------------------------------------------------------------
      (                        group and capture to \3 (optional
                               (matching the most amount possible)):
--------------------------------------------------------------------------------
        \s*                      whitespace (\n, \r, \t, \f, and " ")
                                 (0 or more times (matching the most
                                 amount possible))
--------------------------------------------------------------------------------
        =                        '='
--------------------------------------------------------------------------------
        \s*                      whitespace (\n, \r, \t, \f, and " ")
                                 (0 or more times (matching the most
                                 amount possible))
--------------------------------------------------------------------------------
        (?:                      group, but do not capture:
--------------------------------------------------------------------------------
          "                   '"'
--------------------------------------------------------------------------------
          .*?                      any character except \n (0 or more
                                   times (matching the least amount
                                   possible))
--------------------------------------------------------------------------------
          "                   '"'
--------------------------------------------------------------------------------
         |                        OR
--------------------------------------------------------------------------------
          '                        '\''
--------------------------------------------------------------------------------
          .*?                      any character except \n (0 or more
                                   times (matching the least amount
                                   possible))
--------------------------------------------------------------------------------
          '                        '\''
--------------------------------------------------------------------------------
         |                        OR
--------------------------------------------------------------------------------
          [^'">\s             any character except: ''', '&',
          ]+                       'q', 'u', 'o', 't', ';', '>',
                                   whitespace (\n, \r, \t, \f, and "
                                   ") (1 or more times (matching the
                                   most amount possible))
--------------------------------------------------------------------------------
        )                        end of grouping
--------------------------------------------------------------------------------
      )?                       end of \3 (NOTE: because you are using
                               a quantifier on this capture, only the
                               LAST repetition of the captured
                               pattern will be stored in \3)
--------------------------------------------------------------------------------
    )+                       end of \2 (NOTE: because you are using a
                             quantifier on this capture, only the
                             LAST repetition of the captured pattern
                             will be stored in \2)
--------------------------------------------------------------------------------
    \s*                      whitespace (\n, \r, \t, \f, and " ") (0
                             or more times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
   |                        OR
--------------------------------------------------------------------------------
    \s*                      whitespace (\n, \r, \t, \f, and " ") (0
                             or more times (matching the most amount
                             possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  /?                       '/' (optional (matching the most amount
                           possible))
--------------------------------------------------------------------------------
  >                        '>'