Case-Insensitive Search

How do I make the following work?  I want match.Success to be True regardless of the case.  If the testString = "AAA" or testString = "aAa"  

dim testString as string = "AAa"

Dim match As Match = Regex.Match(testString , "([\s\S])\1\1")
Ray TurnerSenior ConsultantAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
It is a valid regex asking for any arbitrary character repeated 3 times. But then why you are not using just a dot?
Is your target exactly that? Any repetition of a character at least for 3 times, ignoring case? No matter if it is a letter, digit, whitespace ...
0
 
Rgonzo1971Commented:
Hi,


Why not?
(?i)

refer to
http://www.regular-expressions.info/modifiers.html

Regards
0
 
QlemoConnect With a Mentor Batchelor, Developer and EE Topic AdvisorCommented:
\s is whitespace, \S non-whitespace, so your regex is completely wrong.

You might be able to use the Posix notification (not sure about that, but it works in PowerShell): "^[:alpha:]{3}$"
Or case-insensitive search modifier and a character class: "^(?i)[A-Z]{3}$"
Or using a character class only: "^[A-Za-z]{3}$"

This assumes you want to  have exactly 3 letters.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Ray TurnerSenior ConsultantAuthor Commented:
Why is the regex completely wrong?  Are you saying this is not valid? I thought \s\S is the same as .
0
 
Ray TurnerSenior ConsultantAuthor Commented:
Yes.  That's what I am trying to do.
0
 
Ray TurnerSenior ConsultantAuthor Commented:
Sorry,  how do I modify the following to do just that?

Dim match As Match = Regex.Match(testString , "(.)\1\1")
0
 
Ray TurnerSenior ConsultantAuthor Commented:
I solve my problem with the following solution:

Dim match As Match = Regex.Match(testString.ToLower() , "(.)\1\1")
0
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
Dim match As Match = Regex.Match(testString, "(?i)(.)\1\1")
should do also.
0
 
Ray TurnerSenior ConsultantAuthor Commented:
Thanks!  It does indeed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.