Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Regex Problem

by Krambambuli (Deacon)
on Oct 24, 2008 at 08:58 UTC ( #719293=note: print w/ replies, xml ) Need Help??


in reply to Regex Problem

Maybe the following is a bit towards what you want; what exactly is a word would probably need to be specified in more detail:

#!/usr/bin/perl use strict; use warnings; while (<DATA>) { my $line = $_; my $not = ''; if ($line !~ /word1(([,\s]+\w+)?){1,4}\s+word2/) { $not = 'NOT '; } print "$line \tdoes $not match the regexp.\n"; } __DATA__ word1 is made of word2 word1, which is an important thing because of its use and stuff, is ma +de of word2.
prints out
word1 is made of word2 does match the regexp. word1, which is an important thing because of its use and stuff, is ma +de of word2. does NOT match the regexp.

Krambambuli
---


Comment on Re: Regex Problem
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://719293]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (11)
As of 2014-09-18 12:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (113 votes), past polls