我想建立一个正则表达式来匹配下面的字符串。
<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)
不区分大小写匹配的内联修饰符[\/]?
可选地(使用问号)匹配或/使用字符类['"]
匹配"或"xsshere
Match字面意思|
Or<xsshere>
Match字面意思
查看regex101演示