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
FTP not working on Windows Server 2008 IIS 7
How to get unique records based on maximum date?
Customize left_col.phtml properly in Magento - XML beginner!
what msstd in outlook anywhere used for?
Replace line from keyword
Network card disables on reboot
CISCO - ACCESS - DISTRIBUTION - CORE - DO I NEED THEM ALL
ESXi compatible hardware
mail in outbox till another folder is clicked
Sharepoint 3.0 permissions resetting