472,950 Members | 2,345 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,950 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 1568
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: aevans1108 | last post by:
expanding this message to microsoft.public.dotnet.xml Greetings Please direct me to the right group if this is an inappropriate place to post this question. Thanks. I want to format a...
17
by: clintonG | last post by:
I'm using an .aspx tool I found at but as nice as the interface is I think I need to consider using others. Some can generate C# I understand. Your preferences please... <%= Clinton Gallagher ...
3
by: jg | last post by:
I made a mistake somewhere in my vb code and I look, check and read against the articles and help on regex, I still can't find the mistake I made. I know my test string and the test patterns...
7
by: melanieab | last post by:
Hi, I'm trying to use DataView to find the row number in the datatable that contains "Rich" in it so that I can highlight it. It works fine when I enter the entire string (i.e. Richard), but I...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
6
by: Sa¹o Zagoranski | last post by:
Hi, could someone help me putting together a regex expression for my problem? I need my search filter to treat spaces and commas in the query the same way no matter how many there are... ...
15
by: morleyc | last post by:
Hi, i would like to remove a number of characters from my string (\t \r \n which are throughout the string), i know regex can do this but i have no idea how. Any pointers much appreciated. Chris
7
by: =?Utf-8?B?amFj?= | last post by:
Hi, I have problems with following code and don’t find the bug : // Set ArrayList aArray = new ArrayList(); regStr = new Regex(@"\?)*(\d+)\]"); if(text != null && regStr.IsMatch(text))...
1
by: billy.murray | last post by:
I have the following text inside a file which I am trying to parse. I am creating a new RegEx object as follows :- string strRegex = @"({S:\r?\n)(*)(})" {S: INTERLOCK FAIL : Tie bar...
6
by: | last post by:
Hi all, Sorry for the lengthy post but as I learned I should post concise-and-complete code. So the code belows shows that the execution of ValidateAddress consumes a lot of time. In the test...
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...

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.