Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: pick a word contaning reg-ex

by keesturam (Initiate)
on Dec 04, 2012 at 13:31 UTC ( #1007090=note: print w/replies, xml ) Need Help??

in reply to pick a word contaning reg-ex

Oh.! Reply from previous post answers my question as well!!

perl -ne '/(\w*!\w*)/g && print "$1\n";' code_file(s)

Lesson learnt. search for existing threads before posting questions :-)

Replies are listed 'Best First'.
Re^2: pick a word contaning reg-ex
by space_monk (Chaplain) on Dec 04, 2012 at 14:29 UTC

      I just tried the code above and it only prints the first word (update: on each line) that contains an exclamation point.

      #!/perl use warnings; use strict; while(<DATA>){ #print map {"$_\n"} grep{/!/} split; /(\w*!\w*)/g && print "$1\n"; } __DATA__ Mary had a little lamb! , whose fleece! was white! as snow. And everywhere! that Mary went, the lamb was sure! to go. oops!eedaisy

      Produces this:

      lamb! fleece! everywhere! sure! oops!eedaisy
        Oops - try
        while (/(\w*!\w*)/g) { print "$1\n"; }
        A Monk aims to give answers to those who have none, and to learn from those who know more.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007090]
NodeReaper practices with his stiletto

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2018-03-20 04:54 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (247 votes). Check out past polls.