Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Regex Word Pairs

by GrandFather (Saint)
on Aug 15, 2007 at 23:46 UTC ( [id://632889]=note: print w/replies, xml ) Need Help??


in reply to Regex Word Pairs

Depends what you call better:

use strict; use warnings; my $s = 'This is a test'; my @pairs = $s =~ /(?=(\w+ \s+ \w+))\w+ \s+/gx; print join "\n", @pairs;

Prints:

This is is a a test

Update: or if you want @pairs as an AoA:

... my @pairs = map [split], $s =~ /(?=(\w+ \s+ \w+))\w+ \s+/gx; print "@$_\n" for @pairs;

prints:

This is is a a test

DWIM is Perl's answer to Gödel

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (5)
As of 2024-04-24 08:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found