REGEX problem

  • Thread starter Thread starter Kijak
  • Start date Start date
K

Kijak

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
 
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/d...l/cpconRegularExpressionsLanguageElements.asp

Hope this helps
Jay
 
Thanks, but I thought | was OR - mening it would match "The car is driven by
an ok dad" to?

Regards
 
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.
http://msdn.microsoft.com/library/d...l/cpconRegularExpressionsLanguageElements.asp

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

Hope this helps
Jay
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top