How do I write a regular expression that matches a particular string in all combinations of upper and lower case letters except for one?
For example, take the string "SuperMario". What regular expression matches that string in all other combinations of upper and lower case letters?
The regular expression should match:
The regular expression should not match:
Perl compatible regular expression preferred.
You can use this:
/(?!SuperMario)(?i)supermario/
EDIT:
Note that you will have better performances with a lookbehind, if your string contains other things:
/(?i)supermario(?<!(?-i)SuperMario)/
my $s = "Supermario";
if ($s =~ /supermario/i and $s !~ /SuperMario/) {
print "wrong\n";
}
Another method:
/(?:[S](?!uperMario)|s)[Uu][Pp][eE][rR][mM][aA][Rr][iI][oO]/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With