Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

Re: Regexp matching words, not doing what I expect

by JavaFan (Canon)
on May 13, 2009 at 19:36 UTC ( [id://763890]=note: print w/replies, xml ) Need Help??

in reply to Regexp matching words, not doing what I expect

$_ = "hello to all the perl monks"; /\b(([A-Za-z'\-]+) (?-1))\b(?{ say $1 })(*FAIL)/; __END__ hello to to all all the the perl perl monks

Replies are listed 'Best First'.
Re^2: Regexp matching words, not doing what I expect
by AnomalousMonk (Archbishop) on May 13, 2009 at 19:59 UTC
    Or without the extended regex features of 5.10 (basically moritz's approach, but with only one capture):
    >perl -wMstrict -le "my $text = q{hello to 'all' this perl-monk's friends}; my $wchar = qr{ [A-Za-z'-] }xms; my $word = qr{ (?<! $wchar) $wchar+ }xms; while ($text =~ m{ (?= ($word \s+ $word)) }xmsg) { print $1 } " hello to to 'all' 'all' this this perl-monk's perl-monk's friends
      The 5.10 features can easily be avoided: the (?-1) can be replaced by just copying the [A-Za-z'-] part, and the (*FAIL) can be replaced with (?!).

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-06-16 09:42 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.