Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Stumped by regex

by bsdz (Friar)
on Dec 06, 2006 at 15:03 UTC ( [id://588101]=note: print w/replies, xml ) Need Help??


in reply to Stumped by regex

I'm not sure how to do this exactly with a regex but one could use something like: -
use strict; my @names = ( 'Joe John Smith', 'David George', 'Emma Harry Sally Martin', ); foreach (@names) { my @w = split /\s/, (/\s+(\w[\w ]{0,18}\w)\s*$/)[0]; shift @w while @w > 2; print "@w\n"; }
Update: You can replace everything in the foreach scope with: -
(/\s+(\w[\w ]{0,18}\w)\s*$/)[0] =~ /(\w+\s?\w+)$/g;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (3)
As of 2024-04-26 05:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found