Solved

Case-Insensitive Search

Posted on 2015-01-18
9
101 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 50

Expert Comment

by:Rgonzo1971
ID: 40556137
Hi,


Why not?
(?i)

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

Regards
0
 
LVL 69

Assisted Solution

by:Qlemo
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.
0
 

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 .
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 69

Accepted Solution

by:
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 ...
0
 

Author Comment

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

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")
0
 

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")
0
 
LVL 69

Expert Comment

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

Author Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to wrap a merged cells of datagridview column in vs2010 (vb.net) 8 44
vb.net 1 month apart 11 35
VB.Net. Reading xml value 6 29
How to repeat the data 4 16
It’s quite interesting for me as I worked with Excel using vb.net 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 …
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…

840 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