Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Regex tester

by koolgirl (Hermit)
on Aug 24, 2008 at 05:19 UTC ( [id://706494]=note: print w/replies, xml ) Need Help??


in reply to Regex tester

Wow, very nice. I'm going to play around with that one for a bit. I just started learning regex's in depth, so this is a great tool. I have one I constructed as well, which might be useful, if just a simple match test is your aim:
#!usr/bin/perl $my_string = ""; $my_regx = ""; # This program tests regular expressions against a match. if ($my_string =~ /$my_regx/x) print "Matched: " . "\"" . $& . "\"" . "\n"; # print matc +h print "Before match: " . "\"" . $` . "\"" . "\n"; # print data + before match print "After match: " . "\"" . $' . "\"" . "\n"; # print data + after match }else { # do nothing } # end if print "Rockstar Programming Inc. All Rights Reserved\n";
So, now I have yours to explore with and maybe my much simpler "matcher" could possibly be of use to you :)

Replies are listed 'Best First'.
Re^2: Regex tester
by GrandFather (Saint) on Aug 24, 2008 at 21:43 UTC

    There are a few things here that could use a little tidying. First off, the mandatory mantra: Always use strictures (use strict; use warnings; - see The strictures, according to Seuss).

    Of more immediate benefit: if you find you need to include double quote character in a string use qq for quoting instead of " (see perlop's Quote and Quote-like Operators). For example your print statements become:

    print qq{Matched: "$&"\n}; # print match print qq~Before match: "$`"\n~; # print data before match print qq|After match: "$'"\n|; # print data after match

    although you may wish to use a here-doc instead (look for here-doc in the same docs mentioned above):

    print <<STUFF; Matched: "$&" Before match: "$`" After match: "$'" STUFF

    Perl reduces RSI - it saves typing

Log In?
Username:
Password:

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

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

    No recent polls found