Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

How to Ask A Regex Question (With Test::More)

by tphyahoo (Vicar)
on Jul 29, 2005 at 17:11 UTC ( [id://479480]=perltutorial: print w/replies, xml ) Need Help??

This is the second post in the How To Ask a Question (With Test::More) series, and assumes you have read the first, main post.

In this installment, we learn how to use Test::More::like($string, $regex) and the qr quotelike operator to ask regex questions in a sane way. Let's dive right in.

******************BEGIN QUESTION TEMPLATE************************

O Wise Monks, I can't get this regex to do what I want it to do. As you can see, it fails two tests.

use warnings; use strict; use Test::More qw(no_plan); my $emailsregex = qr/\w+@\w+\.(net|com|org)/; while (<DATA>) { like($_, $emailsregex) } __DATA__
I'm on Windows XP system using the standard ActiveState perl distribution.

I got both standard and error output out of my test, into one output file, by running this with > output.txt 2>&1 output.txt.

The output I got was

ok 1 ok 2 not ok 3 # Failed test ( at line 8) # ' # ' # doesn't match '(?-xism:\w+@\w+\.(net|com|org))' not ok 4 # Failed test ( at line 8) # ' # ' # doesn't match '(?-xism:\w+@\w+\.(net|com|org))' ok 5 1..5 # Looks like you failed 2 tests of 5.

What the heck am I doing wrong?

******************END QUESTION TEMPLATE************************

(Debugging the regex is left as an exercise for the reader.)

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (2)
As of 2024-06-23 04:17 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.