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

How to use AND in regex

P: n/a
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,

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


P: n/a
Hi,

Dim r As New
System.Text.RegularExpressions.Regex("^(?=.*?\bhop e\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

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

"kijak" <ki*******@yahoo.dk> wrote in message
news:O6****************@TK2MSFTNGP09.phx.gbl...
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,


Nov 20 '05 #2

P: n/a
Hi,

Dim r As New
System.Text.RegularExpressions.Regex("^(?=.*?\bhop e\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

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

"kijak" <ki*******@yahoo.dk> wrote in message
news:O6****************@TK2MSFTNGP09.phx.gbl...
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,


Nov 20 '05 #3

P: n/a
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
"Ken Tucker [MVP]" <vb***@bellsouth.net> skrev i en meddelelse
news:uM**************@TK2MSFTNGP09.phx.gbl...
Hi,

Dim r As New
System.Text.RegularExpressions.Regex("^(?=.*?\bhop e\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

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

"kijak" <ki*******@yahoo.dk> wrote in message
news:O6****************@TK2MSFTNGP09.phx.gbl...
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,

Nov 20 '05 #4

P: n/a
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
"Ken Tucker [MVP]" <vb***@bellsouth.net> skrev i en meddelelse
news:uM**************@TK2MSFTNGP09.phx.gbl...
Hi,

Dim r As New
System.Text.RegularExpressions.Regex("^(?=.*?\bhop e\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

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

"kijak" <ki*******@yahoo.dk> wrote in message
news:O6****************@TK2MSFTNGP09.phx.gbl...
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,

Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.