• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

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.
0
whos_wee_dug
Asked:
whos_wee_dug
  • 2
  • 2
1 Solution
 
ozoCommented:
^A\s\(w+)\sis\sa\s(\w+)$
0
 
whos_wee_dugAuthor Commented:
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 + "'")
0
 
ozoCommented:
Dim re As New Regex("^(A)\s(\w+)\s(is)\s(a)\s(\w+)$")
0
 
whos_wee_dugAuthor Commented:
thanks once again ozo, you've been a great help.

Cheers,
Col.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now