By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,815 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,815 IT Pros & Developers. It's quick & easy.

REGEX problem

P: n/a
Hi,

Im just starting working with REGEX and got a few problems. Could you
tell me how to test if two strings can be found in another. ei:

String to test: "This is a great car you got"
Look for: "great" AND "car"

and what about upper case

String to test: "This is a great VOLVO you got"
Look for: "VOLVO" AND "car" (and not "volvo AND car")

Just don't get it

Thanks
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Kijak,
Does great need to precede car?

You can use Alternation to match two or more strings with a Regex, something
like:

Const pattern As String = "great|car"
Dim input As String = "The car is driven by a great dad"
Dim ex As New System.Text.RegularExpressions.Regex(pattern)
If ex.IsMatch(input) Then
Debug.WriteLine("Great Car Found!")
End If

A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"Kijak" <ki*******@yahoo.dk> wrote in message
news:97*************************@posting.google.co m...
Hi,

Im just starting working with REGEX and got a few problems. Could you
tell me how to test if two strings can be found in another. ei:

String to test: "This is a great car you got"
Look for: "great" AND "car"

and what about upper case

String to test: "This is a great VOLVO you got"
Look for: "VOLVO" AND "car" (and not "volvo AND car")

Just don't get it

Thanks

Nov 20 '05 #2

P: n/a
Thanks, but I thought | was OR - mening it would match "The car is driven by
an ok dad" to?

Regards
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> skrev i en
meddelelse news:OI**************@TK2MSFTNGP12.phx.gbl...
Kijak,
Does great need to precede car?

You can use Alternation to match two or more strings with a Regex, something like:

Const pattern As String = "great|car"
Dim input As String = "The car is driven by a great dad"
Dim ex As New System.Text.RegularExpressions.Regex(pattern)
If ex.IsMatch(input) Then
Debug.WriteLine("Great Car Found!")
End If

A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"Kijak" <ki*******@yahoo.dk> wrote in message
news:97*************************@posting.google.co m...
Hi,

Im just starting working with REGEX and got a few problems. Could you
tell me how to test if two strings can be found in another. ei:

String to test: "This is a great car you got"
Look for: "great" AND "car"

and what about upper case

String to test: "This is a great VOLVO you got"
Look for: "VOLVO" AND "car" (and not "volvo AND car")

Just don't get it

Thanks


Nov 20 '05 #3

P: n/a
Thanks, but I thought | was OR - mening it would match "The car is driven by
an ok dad" to?

Regards
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> skrev i en
meddelelse news:OI**************@TK2MSFTNGP12.phx.gbl...
Kijak,
Does great need to precede car?

You can use Alternation to match two or more strings with a Regex, something like:

Const pattern As String = "great|car"
Dim input As String = "The car is driven by a great dad"
Dim ex As New System.Text.RegularExpressions.Regex(pattern)
If ex.IsMatch(input) Then
Debug.WriteLine("Great Car Found!")
End If

A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:
http://msdn.microsoft.com/library/de...geElements.asp
Hope this helps
Jay

"Kijak" <ki*******@yahoo.dk> wrote in message
news:97*************************@posting.google.co m...
Hi,

Im just starting working with REGEX and got a few problems. Could you
tell me how to test if two strings can be found in another. ei:

String to test: "This is a great car you got"
Look for: "great" AND "car"

and what about upper case

String to test: "This is a great VOLVO you got"
Look for: "VOLVO" AND "car" (and not "volvo AND car")

Just don't get it

Thanks


Nov 20 '05 #4

P: n/a
Kijak,
Yes | is OR.

Yes it will match your string also. (my mistake).

Which is why I asked if "Does great need to precede car?", as you may need a
complex Alternation.

It also matters what can separate great from car (a space, any white space,
any character...).

In other words, which of the following strings match?
"great car"
"great fast car"
"great car"
"car great"
"car not so great"
"greater carrots"
"carrots are greater"

As I indicated in my original response.
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:

http://msdn.microsoft.com/library/de...geElements.asp

Are both valuable resources, especially the first one, to lean how to create
regular expressions!

Hope this helps
Jay

"kijak" <ki*******@yahoo.dk> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl... Thanks, but I thought | was OR - mening it would match "The car is driven by an ok dad" to?

Regards
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> skrev i en
meddelelse news:OI**************@TK2MSFTNGP12.phx.gbl...
Kijak,
Does great need to precede car?

You can use Alternation to match two or more strings with a Regex,

something
like:

Const pattern As String = "great|car"
Dim input As String = "The car is driven by a great dad"
Dim ex As New System.Text.RegularExpressions.Regex(pattern)
If ex.IsMatch(input) Then
Debug.WriteLine("Great Car Found!")
End If

A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:

http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"Kijak" <ki*******@yahoo.dk> wrote in message
news:97*************************@posting.google.co m...
Hi,

Im just starting working with REGEX and got a few problems. Could you
tell me how to test if two strings can be found in another. ei:

String to test: "This is a great car you got"
Look for: "great" AND "car"

and what about upper case

String to test: "This is a great VOLVO you got"
Look for: "VOLVO" AND "car" (and not "volvo AND car")

Just don't get it

Thanks



Nov 20 '05 #5

P: n/a
Kijak,
Yes | is OR.

Yes it will match your string also. (my mistake).

Which is why I asked if "Does great need to precede car?", as you may need a
complex Alternation.

It also matters what can separate great from car (a space, any white space,
any character...).

In other words, which of the following strings match?
"great car"
"great fast car"
"great car"
"car great"
"car not so great"
"greater carrots"
"carrots are greater"

As I indicated in my original response.
A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:

http://msdn.microsoft.com/library/de...geElements.asp

Are both valuable resources, especially the first one, to lean how to create
regular expressions!

Hope this helps
Jay

"kijak" <ki*******@yahoo.dk> wrote in message
news:u8**************@TK2MSFTNGP10.phx.gbl... Thanks, but I thought | was OR - mening it would match "The car is driven by an ok dad" to?

Regards
"Jay B. Harlow [MVP - Outlook]" <Ja************@msn.com> skrev i en
meddelelse news:OI**************@TK2MSFTNGP12.phx.gbl...
Kijak,
Does great need to precede car?

You can use Alternation to match two or more strings with a Regex,

something
like:

Const pattern As String = "great|car"
Dim input As String = "The car is driven by a great dad"
Dim ex As New System.Text.RegularExpressions.Regex(pattern)
If ex.IsMatch(input) Then
Debug.WriteLine("Great Car Found!")
End If

A tutorial & reference on using regular expressions:
http://www.regular-expressions.info/

The MSDN's documentation on regular expressions:

http://msdn.microsoft.com/library/de...geElements.asp

Hope this helps
Jay

"Kijak" <ki*******@yahoo.dk> wrote in message
news:97*************************@posting.google.co m...
Hi,

Im just starting working with REGEX and got a few problems. Could you
tell me how to test if two strings can be found in another. ei:

String to test: "This is a great car you got"
Look for: "great" AND "car"

and what about upper case

String to test: "This is a great VOLVO you got"
Look for: "VOLVO" AND "car" (and not "volvo AND car")

Just don't get it

Thanks



Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.