Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Regex match for Any number of words?

by haj (Priest)
on Jan 16, 2022 at 11:43 UTC ( #11140502=note: print w/replies, xml ) Need Help??


in reply to Regex match for Any number of words?

There are several ways to do this. A rather short one is:
my $text = " THIS is a variable number of words, spaces and punctuat +ion. "; my @list = split /\W+/,$text;

So I'm splitting the text whenever I found one or more characters which are not words.

I don't know whether eliminating empty strings at the beginning and the end of the list is relevant, so I'm leaving this as an exercise to the reader (hint: grep $_,@list might not do what you want if you consider numbers as words).

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (4)
As of 2022-12-09 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?