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

Re: regex is not working as I intended

by BillKSmith (Monsignor)
on Jan 19, 2018 at 04:25 UTC ( [id://1207500]=note: print w/replies, xml ) Need Help??


in reply to regex is not working as I intended

It is much easier to test the three cases separately.
use strict; use warnings; use Test::More tests=>3; use Regexp::Common 'RE_ALL'; my @cases = ( [q(Now is the time), 'unquoted'], [q('Now is the time'), 'single quoted'], [q("Now is the time"), 'double quoted'], ); foreach my $case (@cases) { $_ = $case->[0]; my $string = /\"(.*)\"/ ? $1 : /\'(.*)\'/ ? $1 : /[^"'].*[^'"]/ ? $& : 'No Match' ; ok($string eq 'Now is the time', "$case->[1] found $string" ); } C:\Users\Bill\forums\monks>perl fireblood.pl 1..3 ok 1 - unquoted found Now is the time ok 2 - single quoted found Now is the time ok 3 - double quoted found Now is the time
Bill

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2024-04-25 21:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found