正则表达式中的模式符号

正则表达式中的模式符号

我是正则表达式的新手,

有人可以为我解释一下这些模式吗:

(<form[^\a]*</form>|<FORM[^\a]*</FORM>)
(method="[a-zA-Z]*|METHOD="[a-zA-Z]*)

答案1

有关 RegExp 的两个重要资源:调试exx正则表达式101

(<form[^\a]*</form>|<FORM[^\a]*</FORM>)

正则表达式可视化

调试器

在此处输入图片描述

正则表达式101


(method="[a-zA-Z]*|METHOD="[a-zA-Z]*)

正则表达式可视化

调试器

在此处输入图片描述

正则表达式101

答案2

https://myregextester.com/index.php#(在字段中输入模式Match pattern并确保已勾选Explain。然后单击Submit):

----------------------------------------------------------------------
  (                        group and capture to \1:
----------------------------------------------------------------------
    <form                    '<form'
----------------------------------------------------------------------
    [^\a]*                   any character except: '\a' (alarm) (0 or
                             more times (matching the most amount
                             possible))
----------------------------------------------------------------------
    </form>                  '</form>'
----------------------------------------------------------------------
   |                        OR
----------------------------------------------------------------------
    <FORM                    '<FORM'
----------------------------------------------------------------------
    [^\a]*                   any character except: '\a' (alarm) (0 or
                             more times (matching the most amount
                             possible))
----------------------------------------------------------------------
    </FORM>                  '</FORM>'
----------------------------------------------------------------------
  )                        end of \1
----------------------------------------------------------------------
                           '\r\n'
----------------------------------------------------------------------
  (                        group and capture to \2:
----------------------------------------------------------------------
    method="                 'method="'
----------------------------------------------------------------------
    [a-zA-Z]*                any character of: 'a' to 'z', 'A' to 'Z'
                             (0 or more times (matching the most
                             amount possible))
----------------------------------------------------------------------
   |                        OR
----------------------------------------------------------------------
    METHOD="                 'METHOD="'
----------------------------------------------------------------------
    [a-zA-Z]*                any character of: 'a' to 'z', 'A' to 'Z'
                             (0 or more times (matching the most
                             amount possible))
----------------------------------------------------------------------
  )                        end of \2
----------------------------------------------------------------------
                           '\r\n'
----------------------------------------------------------------------
)                        end of grouping
----------------------------------------------------------------------

相关内容