471,334 Members | 1,328 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,334 software developers and data experts.

Regex to find a string

I have a string, for example :

string str = "abCdEfGhiJKl";

to find "def", ignoring the case, i'm doing

if (str.toLower().Contains("def"))
{
// do something
}
How to do this with regex ?

Thanks for your help
Aug 22 '08 #1
4 1527
I've founded :

Regex regex = new Regex("[dD][eE][fF]");
if (regex.IsMatch(str))
but is it the best way ?

On 22 août, 10:58, timor.su...@gmail.com wrote:
I have a string, for example :

string str = "abCdEfGhiJKl";

to find "def", ignoring the case, i'm doing

if (str.toLower().Contains("def"))
{
// do something

}

How to do this with regex ?

Thanks for your help
Aug 22 '08 #2
On 22 Aug., 11:57, timor.su...@gmail.com wrote:
I've founded :

Regex regex = new Regex("[dD][eE][fF]");
if (regex.IsMatch(str))

but is it the best way ?

On 22 août, 10:58, timor.su...@gmail.com wrote:
I have a string, for example :
string str = "abCdEfGhiJKl";
to find "def", ignoring the case, i'm doing
if (str.toLower().Contains("def"))
{
// do something
}
How to do this with regex ?
Thanks for your help
You could set the "Options"-property of your Regex to IgnoreCase if
you don't want to check for lower and upper case of every character.

hth,
Kevin Wienhold
Aug 22 '08 #3
ti*********@gmail.com pretended :
I've founded :

Regex regex = new Regex("[dD][eE][fF]");
if (regex.IsMatch(str))
but is it the best way ?
There is also an overload that accepts RegexOptions. Use
RegexOptions.IgnoreCase.

And there is a static variant:
if (Regex.IsMatch(str, "def", RegexOptions.IgnoreCase)) ...

Hans Kesting
Aug 22 '08 #4
this is working well

Thanks you both

:)

On 22 août, 13:00, Hans Kesting <news.han...@spamgourmet.comwrote:
timor.su...@gmail.com pretended :
I've founded :
Regex regex = new Regex("[dD][eE][fF]");
if (regex.IsMatch(str))
but is it the best way ?

There is also an overload that accepts RegexOptions. Use
RegexOptions.IgnoreCase.

And there is a static variant:
if (Regex.IsMatch(str, "def", RegexOptions.IgnoreCase)) ...

Hans Kesting
Aug 22 '08 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

17 posts views Thread by clintonG | last post: by
3 posts views Thread by jg | last post: by
7 posts views Thread by melanieab | last post: by
6 posts views Thread by Sa¹o Zagoranski | last post: by
15 posts views Thread by morleyc | last post: by
7 posts views Thread by =?Utf-8?B?amFj?= | last post: by
1 post views Thread by billy.murray | last post: by
6 posts views Thread by | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.