Case-Insensitive Search

Posted on 2015-01-18
Last Modified: 2015-01-18
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")
Question by:Ray Turner
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
LVL 50

Expert Comment

ID: 40556137

Why not?

refer to

LVL 69

Assisted Solution

Qlemo earned 500 total points
ID: 40556147
\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.

Author Comment

by:Ray Turner
ID: 40556173
Why is the regex completely wrong?  Are you saying this is not valid? I thought \s\S is the same as .
Independent Software Vendors: 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!

LVL 69

Accepted Solution

Qlemo earned 500 total points
ID: 40556178
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 ...

Author Comment

by:Ray Turner
ID: 40556181
Yes.  That's what I am trying to do.

Author Comment

by:Ray Turner
ID: 40556204
Sorry,  how do I modify the following to do just that?

Dim match As Match = Regex.Match(testString , "(.)\1\1")

Author Closing Comment

by:Ray Turner
ID: 40556274
I solve my problem with the following solution:

Dim match As Match = Regex.Match(testString.ToLower() , "(.)\1\1")
LVL 69

Expert Comment

ID: 40556288
Dim match As Match = Regex.Match(testString, "(?i)(.)\1\1")
should do also.

Author Comment

by:Ray Turner
ID: 40556340
Thanks!  It does indeed.

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question