Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

regexp question

by kidd (Curate)
on Aug 19, 2002 at 15:53 UTC ( #191209=perlquestion: print w/replies, xml ) Need Help??
kidd has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks...

Yesterday you helped me with some problem and I was able to solve it, thanks.

Now I have a question:
Is there a way to check if a line has a word of an array(that has a different number of words) using regexp?...

Some example:

my @query = ('red', 'blue', 'white'); my $line = "That is a blue wall";
My goal is to check trough the @query ans see if any word is in $line. Considering that I will not know the values in @query.

At the moment Im using a foreach() loop, that Im hoping to kill with a one liner:

foreach my $query(@query){ next if $query eq ''; print "I found: $query" if $line =~ /\Q$query/; }


Replies are listed 'Best First'.
Re: regexp question
by Abigail-II (Bishop) on Aug 19, 2002 at 16:01 UTC
    { local $" = "|"; $line =~ /@{[map {quotemeta} @query]}/; } worked grrreat... :-)

      Just one more could I check that all the words in the array are in the line?


        By not being smart and wanting it in a single regexp. Use your foreach loop and a counter. Increment the counter for each match found, and compare after the loop whether the counter equals the size of the array. Or just bail out whenever there isn't a match, depending a bit on what exactly you want to do.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://191209]
Approved by Rex(Wrecks)
[makita]: I am doing this:
[makita]: my $sig = $wss->signature( schema => $wsdl, token => $token, sign_types=>'wsa: Action','wsa:To', 'wsu:Timestamp', 'wsa:MessageID',' SOAP-ENV:Body', signer=>DSIG_RSA_S HA1, public_key => $cert,
[Corion]: Oof, I haven't done much with signing SOAP requests. markov is usually somebody good to ask via mail ;)
[makita]: I need to create a SOAP call where are signed more types not only the body
[makita]: I am inspecting it second day :)
[makita]: Thanks
[Discipulus]: better to ask a full SOPW
erix self-flagellates with the cluebat
[erix]: indeed had to be( time make check-world ) > test_run2.output 2>&1

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2017-03-23 08:49 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (285 votes). Check out past polls.