Perl/Regex Tester


Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739

Deprecated: Creation of dynamic property PPDStack::$accum is deprecated in /project/www/devpit.org/mediawiki-1.23.8/includes/parser/Preprocessor_DOM.php on line 754

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/devpit.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409
From Devpit

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
Jump to:
Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
navigation

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/devpit.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409

Deprecated: Constant E_STRICT is deprecated since 8.4, the error level was removed in /project/www/devpit.org/mediawiki-1.23.8/includes/GlobalFunctions.php on line 2409
,
Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 731

Deprecated: ord(): Providing a string that is not one byte long is deprecated. Use ord($str[0]) instead in /project/www/devpit.org/mediawiki-1.23.8/includes/cache/MessageCache.php on line 739
search

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.

#!/usr/bin/perl

use strict;
use warnings;


# Put test-cases for your regex in here.  The 0/1 indicates whether the test
# 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)'],
];


# 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";
                }
        }
}