Solved

Regular Expression, detecting certain words

Posted on 2007-04-08
4
158 Views
Last Modified: 2010-04-23
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
Comment
Question by:whos_wee_dug
  • 2
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 18873597
^A\s\(w+)\sis\sa\s(\w+)$
0
 

Author Comment

by:whos_wee_dug
ID: 18873599
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
 
LVL 84

Accepted Solution

by:
ozo earned 250 total points
ID: 18873605
Dim re As New Regex("^(A)\s(\w+)\s(is)\s(a)\s(\w+)$")
0
 

Author Comment

by:whos_wee_dug
ID: 18873609
thanks once again ozo, you've been a great help.

Cheers,
Col.
0

Featured Post

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Do you hate spam? I do, and I am willing to bet you do as well. I often wonder, though, "if people hate spam so much, why do they still post their email addresses on the web?" I'm not talking about a plain-text posting here. I am referring to the fa…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question