Reputation: 658
I'm trying to catch if a specific string thefolder
contains any uppercase characters.
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
So far I have the below regex but it will also return true for theDirectory
, which is not desired.
(?=.*[A-Z]).+
Its important to note it must exclusively match the specific string thefolder
as this is for an IIS rewrite which must not effect the rest of the site.
Upvotes: 3
Views: 142
Reputation:
This might work. Uses a lookahead to see if thefolder
(length 9) has a
capital letter. If so, it matches.
(?=(?i:thefolder))(?![a-z]{9})(.{9})
(?=
(?i: thefolder )
)
(?! [a-z]{9} )
( .{9} )
In the worst case, there is always permutations (No syntax but class and alternation).
But, this will always result in a large string.
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
Upvotes: 2
Reputation: 4843
If you are just doing an IIS rewrite, you can just match thefolder
and check the Ignore Case check box, then do whatever you need to do.
Try something like this in your rewrite config file:
<rule name="LowerCaseRule1" stopProcessing="true">
<match url="thefolder" ignoreCase="true" />
<action type="Rewrite" url="{ToLower:{URL}}" />
</rule>
Update:
It's a bit convoluted, but this regex should do it.
.*(?=.*[A-Z])([tT][hH][eE][fF][oO][lL][dD][eE][rR]).*
Upvotes: 1
Reputation: 3574
I think this regex is what you are looking for:
^[^A-Z]+$
Here is the example.
This returns:
http://www.example.com/thefolder = true
http://www.example.com/theDirectory = false
http://www.example.com/theFolder = false
http://www.example.com/ThefolDeR = false
http://www.example.com/THEFOLDER = false
If you want to select the exact opposite you can do this:
^.*[A-Z].*$
Here is the example.
This returns:
http://www.example.com/thefolder = false
http://www.example.com/theDirectory = true
http://www.example.com/theFolder = true
http://www.example.com/ThefolDeR = true
http://www.example.com/THEFOLDER = true
Upvotes: -1