in reply to Re: pick a word contaning reg-ex
in thread pick a word contaning reg-ex

(...Presuming you mean: Re: extracting words with certain characters)

C'est rien! :-)

A Monk aims to give answers to those who have none, and to learn from those who know more.

Replies are listed 'Best First'.
Re^3: pick a word contaning reg-ex
by Lotus1 (Vicar) on Dec 04, 2012 at 15:19 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.