• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 108
  • Last Modified:

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")
0
Ray Turner
Asked:
Ray Turner
  • 5
  • 3
2 Solutions
 
Rgonzo1971Commented:
Hi,


Why not?
(?i)

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

Regards
0
 
QlemoC++ DeveloperCommented:
\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
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
QlemoC++ DeveloperCommented:
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
 
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
 
QlemoC++ DeveloperCommented:
Dim match As Match = Regex.Match(testString, "(?i)(.)\1\1")
should do also.
0
 
Ray TurnerSenior ConsultantAuthor Commented:
Thanks!  It does indeed.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now