Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: Regex match for Any number of words?

by haj (Vicar)
on Jan 16, 2022 at 11:43 UTC ( [id://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?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2024-04-24 03:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found