Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Regex Problem

by Krambambuli (Curate)
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
---

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 romping around the Monastery: (5)
As of 2016-09-28 23:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (541 votes). Check out past polls.