我正在尝试捕捉特定字符串 thefolder
是否包含任何大写字符。
http://www.example.com/thefolder = false
http://www.example.com/theDirectory = false
http://www.example.com/theFolder = true
http://www.example.com/ThefolDeR = true
http://www.example.com/THEFOLDER = true
到目前为止,我有以下正则表达式,但它也会为 theDirectory
返回 true,这是不需要的。
(?=.*[A-Z]).+
重要的是要注意,它必须完全匹配特定字符串 thefolder
,因为这是用于 IIS 重写,不能影响站点的其余部分。
最佳答案
这可能行得通。使用先行查看 thefolder
(长度为 9)是否有
大写字母。如果是,则匹配。
(?=(?i:thefolder))(?![a-z]{9})(.{9})
(?=
(?i: thefolder )
)
(?! [a-z]{9} )
( .{9} )
在最坏的情况下,总是存在排列(没有语法,只有类和交替)。
但是,这总是会导致一个大字符串。
T[hH][eE][fF][oO][lL][dD][eE][rR]|[tT]H[eE][fF][oO][lL][dD ][eE][rR]|[tT][hH]E[fF][oO][lL][dD][eE][rR]|[tT][hH][eE]F[oO][lL] [dD][eE][rR]|[tT][hH][eE][fF]O[lL][dD][eE][rR]|[tT][hH][eE][fF][oO ]L[dD][eE][rR]|[tT][hH][eE][fF][oO][lL]D[eE][rR]|[tT][hH][eE][fF] [oO][lL][dD]E[rR]|[tT][hH][eE][fF][oO][lL][dD][eE]R
T [hH] [eE] [fF] [oO] [lL] [dD] [eE] [rR]
| [tT] H [eE] [fF] [oO] [lL] [dD] [eE] [rR]
| [tT] [hH] E [fF] [oO] [lL] [dD] [eE] [rR]
| [tT] [hH] [eE] F [oO] [lL] [dD] [eE] [rR]
| [tT] [hH] [eE] [fF] O [lL] [dD] [eE] [rR]
| [tT] [hH] [eE] [fF] [oO] L [dD] [eE] [rR]
| [tT] [hH] [eE] [fF] [oO] [lL] D [eE] [rR]
| [tT] [hH] [eE] [fF] [oO] [lL] [dD] E [rR]
| [tT] [hH] [eE] [fF] [oO] [lL] [dD] [eE] R
关于正则表达式特定字符串的任何大写变体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32000299/