?
Solved

Regular Expression, detecting certain words

Posted on 2007-04-08
4
Medium Priority
?
161 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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

Create CentOS 7 Newton Packstack Running Keystone

A bug was filed against RDO for the installation of Keystone v3. This guide is designed to walk you through the configuration for using Keystone v3 with Packstack. You will accomplish this using various repos and the Answers file.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We are witnesses that everyone is saying that our children shouldn't "play" with a technology because it is dangerous. This article is going to prove that they are wrong.
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…
Suggested Courses

762 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