How to use AND in regex

  • Thread starter Thread starter kijak
  • Start date Start date
K

kijak

Can anyone describe the best way to use AND in REGEX:

Look for "land" AND "glory"

String: "The land of hope af glory" - MATCH
String: "The land of hope" - NO MATCH

Anyone?

Thanks,
 
Hi,

Dim r As New
System.Text.RegularExpressions.Regex("^(?=.*?\bhope\b)(?=.*?\bglory\b).*$")

Dim s1 As String = "The land of hope of and glory"

Dim s2 As String = "The land of hope"

Debug.WriteLine(r.IsMatch(s1))

Debug.WriteLine(r.IsMatch(s2))



Ken

---------------------------

Can anyone describe the best way to use AND in REGEX:

Look for "land" AND "glory"

String: "The land of hope af glory" - MATCH
String: "The land of hope" - NO MATCH

Anyone?

Thanks,
 
Thanks a lot - that did it!

What about upper case (Glory AND Hope - not glory AND hope)?

And I dont understand ^ at first and ? at the end. It seems to work without
them

Thanks for your help
 

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