Microsoft
Software
Hardware
Network
Question : Do a logical AND in REGULAR EXPRESSIONS
I need a regular expression to return matches only IF a keyword appears in a string AND one or more match words also appear in the string.
Here is an example. I want to return matches for the words "DOGS", "CATS", "GOLDFISH" but only if the word "PETS" is in the string
For example, the sentence "CATS, DOGS AND GOLDFISH ARE POPULAR PETS" would return "CATS DOGS GOLDFISH".
The sentence "DOGS, CATS AND GOLDFISH ARE TYPES OF ANIMALS" would not return anything because PETS is not in the string.
Is there a way to do this with a regular expression? I'm new to regular expressions and would have never dreamed it would be so difficult. I can match words no problem but I can't code the conditional AND to have it not show anything if a given word is not there.
This has drove me crazy all afternoon. Thanks in advance for advice...
I will ultimately be using the expression from VB 2005 using the .net regex library.
Answer : Do a logical AND in REGULAR EXPRESSIONS
This is the correct regular expression.
TerryAtOpus, your RegEx will fail in Example 3!
ozo, you've spoiled
TerryAtOpus
' RegEx instead of fixing it!
1:
(?:(?=.*PETS)|(?<=PETS.*))(?:DOGS|CATS|GOLDFISH)
Random Solutions
Office 2010 pro plus deployment via GPO
return double array in Delphi call to c++
Can I force reconciliation of old email after blackberry enterprise activation?
Exchange 2003 and 2010 coexistent - Outlook in 2010 cannot email to 2003
Install IIS with a vbs script.If supporting files needed pick from a predefined path.
How do I add my read-only attribute back with a .vb script
sql - date
Sharepoint 2010 Advice, WSS vs MOSS
Cant get vista to view my web site correctly!
Difference between Exchange 2010 archiving and Evault archiving