尝试为 /" 构建正则表达式"<xsshere>



我想建立一个正则表达式来匹配下面的字符串。

<xsshere>
'xsshere
"xsshere
'xsshere
/"xsshere
<XSSHERE>
到目前为止,我已经尝试构建以下regex

(?i)('|"|)(xsshere|<xsshere>)

但不幸的是它不匹配下面的字符串

'xsshere
/"xsshere

可以使用

(?i)(?:/?"|\?')xsshere|<xsshere>

参见regex演示。

细节:

  • (?i)-不区分大小写匹配
  • (?:/?"|\?')-可选的/,然后"或可选的字符,然后'字符
  • xsshere- axsshere字符串
  • |-或
  • <xsshere>-<xsshere>字符串。

问题是您没有匹配/,这是可选的,可以在字符类中匹配它们中的任何一个。

'"不是可选的,但也可以在字符类中。

(?i)[\/]?['"]xsshere|<xsshere>

在部分中,模式匹配:

  • (?i)不区分大小写匹配的内联修饰符
  • [\/]?可选地(使用问号)匹配或/使用字符类
  • ['"]匹配"或"xsshereMatch字面意思
  • |Or
  • <xsshere>Match字面意思

查看regex101演示

相关内容

最新更新