Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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 pondering the Monastery: (3)
As of 2023-03-24 02:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Which type of climate do you prefer to live in?






    Results (60 votes). Check out past polls.

    Notices?