Reputation: 63
I´m new to regular expressions, I need find one phrase in a piece of text (case insensitive), for example:
Text : FindThis("This is example text")
I need get "FindThis" to locate my phrase regardless of the case of the text.
I've tried this:
static Regex text= new Regex("(FindThis\\(['|\"])([^'\"]*)");
Upvotes: 2
Views: 6154
Reputation: 10191
You can do this by using the RegexOptions.IgnoreCase enum. Here's an example:
var result = Regex.IsMatch("Here's some FINDTHIS Text", // the text to search in
"FindThis", // this is the text we're looking for
RegexOptions.IgnoreCase); // specifies that it's not case sensitive
Note that in this case our regex pattern is actually just the text we're looking for. It could equally be a much more complex pattern.
I would check that the Contains method doesn't do what you're looking for? It's a lot simpler!
Upvotes: 1
Reputation: 1273
Case sensitive should be "on" by default. You can pass the option to ignore case when you do the match.
Here's an example: http://www.dotnetperls.com/regex
Upvotes: 3