Solved

Case-Insensitive Search

Posted on 2015-01-18
9
100 Views
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")
0
Comment
Question by:Ray Turner
  • 5
  • 3
9 Comments
 
LVL 48

Expert Comment

by:Rgonzo1971
Comment Utility
Hi,


Why not?
(?i)

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

Regards
0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 500 total points
Comment Utility
\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
 

Author Comment

by:Ray Turner
Comment Utility
Why is the regex completely wrong?  Are you saying this is not valid? I thought \s\S is the same as .
0
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 

Author Comment

by:Ray Turner
Comment Utility
Yes.  That's what I am trying to do.
0
 

Author Comment

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

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

Author Closing Comment

by:Ray Turner
Comment Utility
I solve my problem with the following solution:

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

Expert Comment

by:Qlemo
Comment Utility
Dim match As Match = Regex.Match(testString, "(?i)(.)\1\1")
should do also.
0
 

Author Comment

by:Ray Turner
Comment Utility
Thanks!  It does indeed.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

I have been reconstructing a PHP-based application that has grown into a full blown interface system over the last ten years by a developer that has now gone into business for himself building websites. I am not incredibly fond of writing PHP code o…
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now