Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Regex match for Any number of words?

by kcott (Bishop)
on Jan 16, 2022 at 11:40 UTC ( #11140501=note: print w/replies, xml ) Need Help??


in reply to Regex match for Any number of words?

G'day sbrothy,

It sounds like you just need "split /\W+/, $string"; although, I don't know what the "C++ Boost" connection is.

$ perl -E 'say for split /\W+/, " THIS is a variable number of words, +spaces and punctuation. "' THIS is a variable number of words spaces and punctuation

Is the string you showed representative of your data? Do you have words with hyphens or apostrophes? Are sentences with leading whitespace normal?

The simplicity of my solution may be invalid. Perhaps you need something closer to:

$ perl -E 'say for split /[ ,.]+/, " THIS is a variable number of word +s, spaces and punctuation. " =~ s/^[ ,.]*//r' THIS is a variable number of words spaces and punctuation

— Ken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (2)
As of 2022-05-20 03:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (72 votes). Check out past polls.

    Notices?