Perl/Regex Tester

This is a handy way to test a regular expression you aren't sure about. You can put as many test cases as you want and the output tells you at a glance when one fails.


 * 1) !/usr/bin/perl

use strict; use warnings;


 * 1) Put test-cases for your regex in here.  The 0/1 indicates whether the test
 * 2) case should match the string that follows.

my $tests = [ [0, '_L(float)'], [0, '_L (float)'], [0, 'a _L(float)'], [1, 'a_L(float)'], [1, '_La(float)'], [1, 'yes(float)'], [1, 'yes (float)'], [1, 'a yes(float)'], ];


 * 1) Put the regex you want to test in here.

my $regex = qr/(^|\s)(?!_L\s*\\S+\s*\(float\)/s;

foreach my $test (@$tests) { if($test->[1] =~ $regex) { if($test->[0]) { print "$test->[1] okay\n"; } else { print "$test->[1] FAILED!\n"; }       } else { if($test->[0]) { print "$test->[1] FAILED!\n"; } else { print "$test->[1] okay\n"; }       } }