Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Re: Strip user-defined words with regexp

by Limbic~Region (Chancellor)
on Mar 04, 2004 at 14:54 UTC ( [id://333879]=note: print w/replies, xml ) Need Help??


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

rnahi,
"but it gets the job done :)."

Sorry to nitpick, but actually it doesn't. The first two words were being desired of each sentence.
L~R

Updated to clarify Updated is in italics. I am still wrong because of a misinterpretation of the OP's requirements.

  • Comment on Re: Re: Strip user-defined words with regexp

Replies are listed 'Best First'.
Re: Re: Re: Strip user-defined words with regexp
by rnahi (Curate) on Mar 04, 2004 at 16:09 UTC

    Did you try it?

    It prints the first 2 words as defined by the OP.

      rnahi,
      Yes I did - against the $msg in my post. The problem is my original understanding of the OP's requirements. I was thinking there would be multiple sentences in a given string and the first two words of each sentence was required. There has been clarification of the requirements and you are correct - sorry.

      Cheers - L~R

Re: Re: Re: Strip user-defined words with regexp
by Marcello (Hermit) on Mar 04, 2004 at 15:03 UTC
    I think my original post was a bit too unclear.

    I am looking for at most the first two words. So it may be zero, one or two.

    I've modified his code to:
    my $firstWord = undef; my $secondWord = undef; my $i = 0; while ($message =~ /([A-Za-z0-9]+)/g) { if ($i == 0) { $firstWord = $1; } elsif ($i == 1) { $secondWord = $1; last; } $i++; }
    which does exactly what I was looking for. I only tried to do it in one regexp.

    Thanks, Marcel

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://333879]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 17:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found