Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: parse a string

by talexb (Chancellor)
on May 03, 2002 at 14:46 UTC ( [id://163801]=note: print w/replies, xml ) Need Help??


in reply to parse a string

Something like
my $String = " something, something, something, this "; my ( $LastWord ) = $String =~ m/(\w+)\s$/;
would probably work. The '$' anchors the pattern to the end of the string, and the brackets around the LastWord variable are to keep things in a list context.

--t. alex

"Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

Replies are listed 'Best First'.
Re: Re: parse a string
by Molt (Chaplain) on May 03, 2002 at 15:05 UTC

    This works provided the last section consists of only alphanumerics, since \w won't match anything else. Try this on the string 'Some people don't' and it only matches the 't', using the \S solution is probably safer in the long term.

    Nice use of the inline substitution though, really should get more used to using that idiom.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2024-04-23 22:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found