in reply to Re: Strip user-defined words with regexp
in thread Strip user-defined words with regexp

Out of curiosity: why not just
my ($word1, $word2) = split(/[^A-Za-z0-9]+/, $message);
?

Marcel

Replies are listed 'Best First'.
Re: Re: Re: Strip user-defined words with regexp
by BrowserUk (Patriarch) on Mar 04, 2004 at 19:56 UTC

    Given the OP's examplei input

    With the grep

    $message = "\n +_ ABC1_\n2 3 4"; print join'|', ( grep $_, split /[^A-Za-z0-9]+/ , $message )[0,1]; ABC1|2

    Without

    $message = "\n +_ ABC1_\n2 3 4"; print join'|', split /[^A-Za-z0-9]+/ , $message; |ABC1|2|3|4

    You'll notice the null leading element.

    The list slice is pretty redundant, but it does make it obvious that you are only wanting the first two.


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail