Wrox Programmer Forums
BOOK: Beginning Regular Expressions
This is the forum to discuss the Wrox book Beginning Regular Expressions by Andrew Watt; ISBN: 9780764574894
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Regular Expressions section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old February 25th, 2005, 09:11 PM
Registered User
Join Date: Feb 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default "And" ing Regular Expression

How can specify multiple words must be present in a word. For eg. Find all sentences that has words "cat", "dog" and "birds" in any order.

So this pattern should match following sentences
All cats are neither dogs nor birds.
All birds are neither dogs nor cats.

But should not match following sentences.
  All cats are not dogs.
All birds are neither not cats.

Old March 9th, 2005, 04:35 PM
Registered User
Join Date: Mar 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts

  I'm far from an expert, so I COULD be wrong, but I don't think that there is an AND within the regular expression construct set. However, I took your examples, put them into a text file and wrote a vb.net app which successfully identifies the sentences containing cat, dog and bird. I used regular expression matching once for each word and used a boolean variable to identify the correct sentences. I will happily share the code with you. I can email the zipped app to you if you have vb.net or just copy the logic into a text file and send it to you or whatever works for you. Let me know here or at:

Ron DelPorto
Lecturer, Computer Science
Penn State Erie, The Behrend College

R. W. DelPorto
Old March 16th, 2005, 12:25 PM
Friend of Wrox
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts

In perl you do:


while(<>) {
        next unless (/cat/ && /dog/ && /bird/) ;


test data
$ echo All cats are neither dogs nor birds | ./tmp.pl
All cats are neither dogs nor birds
$ echo All cats are neither dogs nor balloons | ./tmp.pl


Don't Stand on your head - you'll get footprints in your hair. http://www.charlieharvey.org.uk

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular Expression NewToXSL ASP.NET 1.0 and 1.1 Basics 1 June 13th, 2006 02:52 PM
regular expression if-then smay Javascript 4 July 5th, 2005 12:10 PM
Regular Expression DARSIN General .NET 2 November 9th, 2004 08:30 AM
Regular expression help!!! alex_read Javascript 4 August 18th, 2004 03:44 AM
Regular Expression Help Hadware .NET Web Services 3 November 4th, 2003 10:51 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.