Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: 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__ timmytimmers@aol.com hillary-hillers@aol.com garbygerbil@herbill.gerbil.org garbygerbil@herbill.gorgil.org reginald_reggers@aol.com
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 emailsregex.pl > output.txt 2>&1 output.txt.

The output I got was

ok 1 ok 2 not ok 3 # Failed test (emailsregex.pl at line 8) # 'garbygerbil@herbill.gerbil.org # ' # doesn't match '(?-xism:\w+@\w+\.(net|com|org))' not ok 4 # Failed test (emailsregex.pl at line 8) # 'garbygerbil@herbill.gorgil.org # ' # 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.)


In reply to How to Ask a Regex Question (with Test::More) (repost, with Sitedocclan approval) by tphyahoo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2024-04-18 21:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found