Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: the best way to separate a string into words (contractions)

by tye (Sage)
on Jan 20, 2009 at 02:11 UTC ( [id://737454]=note: print w/replies, xml ) Need Help??


in reply to the best way to separate a string into words

For one definition of "split" and "words", I'd use:

my @words= $string =~ /(\w+(?:'\w+)*)/g;

Which would give you words like qw( split and words I'd use ) not like qw( "split" and "words", ) nor like qw( words I d use ).

Update: Or even, allow hyphenated-word capturing:

my @words= $string =~ /(\w+(?:[-']\w+)*)/g;

- tye        

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-25 07:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found