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
WebSphere Application Server Network Deployment
javax.servlet.jsp.JspExcep
tion: Cannot retrieve definition for form bean null on action
Cannot RDP anymore
Microsoft Information Store stalling issues
setting text of a dynamic dom element using javascript
Major help is needed customizing the Windows 7 default user profile
Problem with Microsoft Transporter Suite
User's Web-Based AOL Mail is sending spam to all his contacts
delete text from column B that exists in column A - Excel
Why does a SAV 10.2.4.4000 new installation show up as 10.1.9.9000?