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
Outlook2007/ Exchange: Need password to connect
Import text file - definition (field name, delimited, lng) based on a table
PHP: import several RSS feeds into MySQL
Quickr..How do I edit the tabs on the home page of my place? I want to add a tab
MySQL Rows to Columns by Group
Inserting Rows in Excel with VBA
Can I add multi-millions of records to SQL database while replication is on? Will it work?
How do i factory reset netvanta 1524st switch from the cli command line?
lower lights
Registry key property value