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
OCS 2007 R2 and Cisco call manager
HTTP Error 404.3 on IIS 7.0
GUID of a ActiveX OCX
PC reliability study
WIN Network on SBS 2K3 server has disappeared
How can I send HTML formatted emails to someone who signs up on my site
Multicast session fails to open on secondary site server.
Is possible to just to use a wireless router to extend wireless access to wireless access points?
Repeated Windows Update
how to find my Symantec pcAnywhere serial number