• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 114
  • 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
 
QlemoBatchelor, 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
 
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
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
QlemoBatchelor, 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
 
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.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

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