473,471 Members | 1,750 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1582
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.