Link to home
Start Free TrialLog in
Avatar of whos_wee_dug
whos_wee_dug

asked on

Regular Expression, detecting certain words

Hi,

I've got a regular expression that checks if sentences such as "A duck is a bird" or "A kitten is a cat" are valid:

^(A)\s\w+\s(is)\s(a)\s\w+$

I'm using vb.net and I want to tell which words are different, i.e I want to pickup from the first sentence "duck" and "bird" and "kitten" and "cat" from the second one.  How can I do this?

Cheers,
Col.
Avatar of ozo
ozo
Flag of United States of America image

^A\s\(w+)\sis\sa\s(\w+)$
Avatar of whos_wee_dug
whos_wee_dug

ASKER

Also, I tried this but it didn't quite work:

        Dim test As String = "A duck is a bird"
        Dim re As New Regex("^(A)\s\w+\s(is)\s(a)\s\w+$")
        test = re.Replace(test, "$1 $2 $3 $4 $5")
        Response.Write("<br/>'" + test + "'")
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks once again ozo, you've been a great help.

Cheers,
Col.