Solved

Regular Expression, detecting certain words

Posted on 2007-04-08
4
155 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now