Revision history for Regexp-Wildcards
+0.06 2007-06-26 12:40 UTC
+ + Add : SQL '%' and '_' wildcards (with corresponding pod & tests).
+ + Fix : Typos in pod (looks like this will never end...).
+
0.05 2007-06-22 14:40 UTC
+ Add : Windows strange behaviours caveat.
+ Chg : Simplified bracket prefix.
--- #YAML:1.0
name: Regexp-Wildcards
-version: 0.05
+version: 0.06
abstract: Converts wildcard expressions to Perl regular expressions.
license: perl
generated_by: ExtUtils::MakeMaker version 6.32
VERSION_FROM => 'lib/Regexp/Wildcards.pm',
ABSTRACT_FROM => 'lib/Regexp/Wildcards.pm',
PL_FILES => {},
- PREREQ_PM => {
+ PREREQ_PM => {
'Test::More' => 0,
'Text::Balanced' => 0,
},
- dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+ dist => {
+ PREOP => 'pod2text lib/Regexp/Wildcards.pm > $(DISTVNAME)/README',
+ COMPRESS => 'gzip -9f', SUFFIX => 'gz'
+ },
clean => { FILES => 'Regexp-Wildcards-*' },
);
expressions.
VERSION
- Version 0.05
+ Version 0.06
SYNOPSIS
use Regexp::Wildcards qw/wc2re/;
$re = wc2re 'a{b?,c}*' => 'unix'; # Do it Unix style.
$re = wc2re 'a?,b*' => 'win32'; # Do it Windows style.
$re = wc2re '*{x,y}?' => 'jokers'; # Process the jokers & escape the rest.
+ $re = wc2re '%a_c%' => 'sql'; # Turn SQL wildcards into regexps.
DESCRIPTION
In many situations, users may want to specify patterns to match but
don't need the full power of regexps. Wildcards make one of those sets
of simplified rules. This module converts wildcard expressions to Perl
regular expressions, so that you can use them for matching. It handles
- the "*" and "?" jokers, as well as Unix bracketed alternatives "{,}",
- and uses the backspace ("\") as an escape character. Wrappers are
- provided to mimic the behaviour of Windows and Unix shells.
+ the "*" and "?" shell jokers, as well as Unix bracketed alternatives
+ "{,}", but also "%" and "_" SQL wildcards. Backspace ("\") is used as an
+ escape character. Wrappers are provided to mimic the behaviour of
+ Windows and Unix shells.
VARIABLES
These variables control if the wildcards jokers and brackets must
capture their match. They can be globally set by writing in your program
$Regexp::Wildcards::CaptureSingle = 1;
- # From then, the '?' joker is capturing
+ # From then, "exactly one" wildcards are capturing
or can be locally specified via "local"
{
- local $Regexp::Wildcards::CaptureAny = 1;
- # In this block, the '?' joker is capturing.
+ local $Regexp::Wildcards::CaptureSingle = 1;
+ # In this block, "exactly one" wildcards are capturing.
...
}
# Back to the situation from before the block
functions.
$CaptureSingle
- When this variable is true, each occurence of the unescaped "?" joker is
- made capturing in the resulting regexp (they are be replaced by "(.)").
- Otherwise, they are just replaced by ".". Default is the latter.
+ When this variable is true, each occurence of unescaped *"exactly one"*
+ wildcards (i.e. "?" jokers or "_" for SQL wildcards) are made capturing
+ in the resulting regexp (they are be replaced by "(.)"). Otherwise, they
+ are just replaced by ".". Default is the latter.
+ For jokers :
'a???b\\??' is translated to 'a(.)(.)(.)b\\?(.)' if $CaptureSingle is true
'a...b\\?.' otherwise (default)
+ For SQL wildcards :
+ 'a___b\\__' is translated to 'a(.)(.)(.)b\\_(.)' if $CaptureSingle is true
+ 'a...b\\_.' otherwise (default)
+
$CaptureAny
- By default this variable is false, and successions of unescaped "*"
- jokers are replaced by one single ".*". When it evalutes to true, those
- sequences of "*" are made into one capture, which is greedy ("(.*)") for
+ By default this variable is false, and successions of unescaped *"any"*
+ wildcards (i.e. "*" jokers or "%" for SQL wildcards) are replaced by one
+ single ".*". When it evalutes to true, those sequences of *"any"*
+ wildcards are made into one capture, which is greedy ("(.*)") for
"$CaptureAny > 0" and otherwise non-greedy ("(.*?)").
+ For jokers :
'a***b\\**' is translated to 'a.*b\\*.*' if $CaptureAny is false (default)
'a(.*)b\\*(.*)' if $CaptureAny > 0
'a(.*?)b\\*(.*?)' otherwise
+ For SQL wildcards :
+ 'a%%%b\\%%' is translated to 'a.*b\\%.*' if $CaptureAny is false (default)
+ 'a(.*)b\\%(.*)' if $CaptureAny > 0
+ 'a(.*?)b\\%(.*?)' otherwise
+
$CaptureBrackets
If this variable is set to true, valid brackets constructs are made into
"( | )" captures, and otherwise they are replaced by non-capturing
"wc2re_jokers"
This function takes as its only argument the wildcard string to process,
and returns the corresponding regular expression where the jokers "?"
- and "*" have been translated into their regexp equivalents (see
- "VARIABLES" for more details). All other unprotected regexp
- metacharacters are escaped.
+ (*"exactly one"*) and "*" (*"any"*) have been translated into their
+ regexp equivalents (see "VARIABLES" for more details). All other
+ unprotected regexp metacharacters are escaped.
# Everything is escaped.
print 'ok' if wc2re_jokers('{a{b,c}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
+ "wc2re_sql"
+ Similar to the precedent, but for the SQL wildcards "_" (*"exactly
+ one"*) and "%" (*"any"*). All other unprotected regexp metacharacters
+ are escaped.
+
"wc2re_unix"
- Similar to the precedent, but this one conforms to standard Unix shell
- wildcard rules. It successively escapes all unprotected regexp special
- characters that doesn't hold any meaning for wildcards, turns jokers
- into their regexp equivalents (see "wc2re_jokers"), and changes
- bracketed blocks into (possibly capturing) alternations as described in
+ This function conforms to standard Unix shell wildcard rules. It
+ successively escapes all unprotected regexp special characters that
+ doesn't hold any meaning for wildcards, turns "?" and "*" jokers into
+ their regexp equivalents (see "wc2re_jokers"), and changes bracketed
+ blocks into (possibly capturing) alternations as described in
"VARIABLES". If brackets are unbalanced, it tries to substitute as many
of them as possible, and then escape the remaining "{" and "}". Commas
outside of any bracket-delimited block are also escaped.
print 'ok' if wc2re_unix('{a{b,c\\}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
"wc2re_win32"
- This one works just like the two before, but for Windows wildcards.
+ This one works just like the one before, but for Windows wildcards.
Bracketed blocks are no longer handled (which means that brackets are
escaped), but you can provide a comma-separated list of items.
argument is the wildcard expression, and the second one is the type of
rules to apply which can be :
- 'unix', 'win32', 'jokers'
+ 'unix', 'win32', 'jokers', 'sql'
For one of those raw rule names, "wc2re" simply maps to
- "wc2re_unix", "wc2re_win32" and "wc2re_jokers" respectively.
+ "wc2re_unix", "wc2re_win32", "wc2re_jokers" and "wc2re_sql"
+ respectively.
$^O If you supply the Perl operating system name, the call is deferred
to "wc2re_win32" for $^O equal to 'dos', 'os2', 'MSWin32' or
$re = wc2re 'a{b,c}*' => $^O;
EXPORT
- These four functions are exported only on request : "wc2re",
- "wc2re_unix", "wc2re_win32" and "wc2re_jokers". The variables are not
- exported.
+ These five functions are exported only on request : "wc2re",
+ "wc2re_unix", "wc2re_win32", "wc2re_jokers" and "wc2re_sql". The
+ variables are not exported.
DEPENDENCIES
Text::Balanced, which is bundled with perl since version 5.7.3
=head1 VERSION
-Version 0.05
+Version 0.06
=cut
-our $VERSION = '0.05';
+our $VERSION = '0.06';
=head1 SYNOPSIS
$re = wc2re 'a{b?,c}*' => 'unix'; # Do it Unix style.
$re = wc2re 'a?,b*' => 'win32'; # Do it Windows style.
$re = wc2re '*{x,y}?' => 'jokers'; # Process the jokers & escape the rest.
+ $re = wc2re '%a_c%' => 'sql'; # Turn SQL wildcards into regexps.
=head1 DESCRIPTION
-In many situations, users may want to specify patterns to match but don't need the full power of regexps. Wildcards make one of those sets of simplified rules. This module converts wildcard expressions to Perl regular expressions, so that you can use them for matching. It handles the C<*> and C<?> jokers, as well as Unix bracketed alternatives C<{,}>, and uses the backspace (C<\>) as an escape character. Wrappers are provided to mimic the behaviour of Windows and Unix shells.
+In many situations, users may want to specify patterns to match but don't need the full power of regexps. Wildcards make one of those sets of simplified rules. This module converts wildcard expressions to Perl regular expressions, so that you can use them for matching. It handles the C<*> and C<?> shell jokers, as well as Unix bracketed alternatives C<{,}>, but also C<%> and C<_> SQL wildcards. Backspace (C<\>) is used as an escape character. Wrappers are provided to mimic the behaviour of Windows and Unix shells.
=head1 VARIABLES
These variables control if the wildcards jokers and brackets must capture their match. They can be globally set by writing in your program
$Regexp::Wildcards::CaptureSingle = 1;
- # From then, the '?' joker is capturing
+ # From then, "exactly one" wildcards are capturing
or can be locally specified via C<local>
{
- local $Regexp::Wildcards::CaptureAny = 1;
- # In this block, the '?' joker is capturing.
+ local $Regexp::Wildcards::CaptureSingle = 1;
+ # In this block, "exactly one" wildcards are capturing.
...
}
# Back to the situation from before the block
=head2 C<$CaptureSingle>
-When this variable is true, each occurence of the unescaped C<?> joker is made capturing in the resulting regexp (they are be replaced by C<(.)>). Otherwise, they are just replaced by C<.>. Default is the latter.
+When this variable is true, each occurence of unescaped I<"exactly one"> wildcards (i.e. C<?> jokers or C<_> for SQL wildcards) are made capturing in the resulting regexp (they are be replaced by C<(.)>). Otherwise, they are just replaced by C<.>. Default is the latter.
+ For jokers :
'a???b\\??' is translated to 'a(.)(.)(.)b\\?(.)' if $CaptureSingle is true
'a...b\\?.' otherwise (default)
+ For SQL wildcards :
+ 'a___b\\__' is translated to 'a(.)(.)(.)b\\_(.)' if $CaptureSingle is true
+ 'a...b\\_.' otherwise (default)
+
=cut
our $CaptureSingle = 0;
+sub capture_single {
+ return $CaptureSingle ? '(.)'
+ : '.';
+}
+
=head2 C<$CaptureAny>
-By default this variable is false, and successions of unescaped C<*> jokers are replaced by B<one> single C<.*>. When it evalutes to true, those sequences of C<*> are made into B<one> capture, which is greedy (C<(.*)>) for C<$CaptureAny E<gt> 0> and otherwise non-greedy (C<(.*?)>).
+By default this variable is false, and successions of unescaped I<"any"> wildcards (i.e. C<*> jokers or C<%> for SQL wildcards) are replaced by B<one> single C<.*>. When it evalutes to true, those sequences of I<"any"> wildcards are made into B<one> capture, which is greedy (C<(.*)>) for C<$CaptureAny E<gt> 0> and otherwise non-greedy (C<(.*?)>).
+ For jokers :
'a***b\\**' is translated to 'a.*b\\*.*' if $CaptureAny is false (default)
'a(.*)b\\*(.*)' if $CaptureAny > 0
'a(.*?)b\\*(.*?)' otherwise
+ For SQL wildcards :
+ 'a%%%b\\%%' is translated to 'a.*b\\%.*' if $CaptureAny is false (default)
+ 'a(.*)b\\%(.*)' if $CaptureAny > 0
+ 'a(.*?)b\\%(.*?)' otherwise
+
=cut
our $CaptureAny = 0;
+sub capture_any {
+ return $CaptureAny ? (($CaptureAny > 0) ? '(.*)'
+ : '(.*?)')
+ : '.*';
+}
+
=head2 C<$CaptureBrackets>
If this variable is set to true, valid brackets constructs are made into C<( | )> captures, and otherwise they are replaced by non-capturing alternations (C<(?: | >)), which is the default.
our $CaptureBrackets = 0;
+sub capture_brackets {
+ return $CaptureBrackets ? '('
+ : '(?:';
+}
+
=head1 FUNCTIONS
=head2 C<wc2re_jokers>
-This function takes as its only argument the wildcard string to process, and returns the corresponding regular expression where the jokers C<?> and C<*> have been translated into their regexp equivalents (see L</VARIABLES> for more details). All other unprotected regexp metacharacters are escaped.
+This function takes as its only argument the wildcard string to process, and returns the corresponding regular expression where the jokers C<?> (I<"exactly one">) and C<*> (I<"any">) have been translated into their regexp equivalents (see L</VARIABLES> for more details). All other unprotected regexp metacharacters are escaped.
# Everything is escaped.
print 'ok' if wc2re_jokers('{a{b,c}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
return do_jokers($wc);
}
+=head2 C<wc2re_sql>
+
+Similar to the precedent, but for the SQL wildcards C<_> (I<"exactly one">) and C<%> (I<"any">). All other unprotected regexp metacharacters are escaped.
+
+=cut
+
+sub wc2re_sql {
+ my ($wc) = @_;
+ $wc =~ s/(?<!\\)((?:\\\\)*[^\w\s%\\])/\\$1/g;
+ return do_sql($wc);
+}
+
=head2 C<wc2re_unix>
-Similar to the precedent, but this one conforms to standard Unix shell wildcard rules. It successively escapes all unprotected regexp special characters that doesn't hold any meaning for wildcards, turns jokers into their regexp equivalents (see L</wc2re_jokers>), and changes bracketed blocks into (possibly capturing) alternations as described in L</VARIABLES>. If brackets are unbalanced, it tries to substitute as many of them as possible, and then escape the remaining C<{> and C<}>. Commas outside of any bracket-delimited block are also escaped.
+This function conforms to standard Unix shell wildcard rules. It successively escapes all unprotected regexp special characters that doesn't hold any meaning for wildcards, turns C<?> and C<*> jokers into their regexp equivalents (see L</wc2re_jokers>), and changes bracketed blocks into (possibly capturing) alternations as described in L</VARIABLES>. If brackets are unbalanced, it tries to substitute as many of them as possible, and then escape the remaining C<{> and C<}>. Commas outside of any bracket-delimited block are also escaped.
# This is a valid bracket expression, and is completely translated.
print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)';
=head2 C<wc2re_win32>
-This one works just like the two before, but for Windows wildcards. Bracketed blocks are no longer handled (which means that brackets are escaped), but you can provide a comma-separated list of items.
+This one works just like the one before, but for Windows wildcards. Bracketed blocks are no longer handled (which means that brackets are escaped), but you can provide a comma-separated list of items.
# All the brackets are escaped, and commas are seen as list delimiters.
print 'ok' if wc2re_win32('{a{b,c}d,e}') eq '(?:\\{a\\{b|c\\}d|e\\})';
$wc =~ s/(?<!\\)((?:\\\\)*[^\w\s?*\\,])/\\$1/g;
my $re = do_jokers($wc);
if ($re =~ /(?<!\\)(?:\\\\)*,/) { # win32 allows comma-separated lists
- $re = ($CaptureBrackets ? '(' : '(?:') . do_commas($re) . ')';
+ $re = capture_brackets . do_commas($re) . ')';
}
return $re;
}
=over 4
-=item C<'unix'>, C<'win32'>, C<'jokers'>
+=item C<'unix'>, C<'win32'>, C<'jokers'>, C<'sql'>
-For one of those raw rule names, C<wc2re> simply maps to C<wc2re_unix>, C<wc2re_win32> and C<wc2re_jokers> respectively.
+For one of those raw rule names, C<wc2re> simply maps to C<wc2re_unix>, C<wc2re_win32>, C<wc2re_jokers> and C<wc2re_sql> respectively.
=item C<$^O>
my %types = (
'jokers' => \&wc2re_jokers,
+ 'sql' => \&wc2re_sql,
'unix' => \&wc2re_unix,
map { lc $_ => \&wc2re_win32 } qw/win32 dos os2 MSWin32 cygwin/
);
=head1 EXPORT
-These four functions are exported only on request : C<wc2re>, C<wc2re_unix>, C<wc2re_win32> and C<wc2re_jokers>. The variables are not exported.
+These five functions are exported only on request : C<wc2re>, C<wc2re_unix>, C<wc2re_win32>, C<wc2re_jokers> and C<wc2re_sql>. The variables are not exported.
=cut
use base qw/Exporter/;
our @EXPORT = ();
-our @EXPORT_OK = ('wc2re', map { 'wc2re_' . $_ } keys %types);
-our @EXPORT_FAIL = qw/extract do_jokers do_commas do_brackets do_bracketed/;
+our @EXPORT_OK = ('wc2re', map { 'wc2re_'.$_ } keys %types);
+our @EXPORT_FAIL = qw/extract/,
+ (map { 'do_'.$_ } qw/jokers sql commas brackets bracketed/),
+ (map { 'capture_'.$_ } qw/single any brackets/);
our %EXPORT_TAGS = ( all => [ @EXPORT_OK ] );
=head1 DEPENDENCIES
# escape an odd number of \ that doesn't protect a regexp/wildcard special char
s/(?<!\\)((?:\\\\)*\\(?:[\w\s]|$))/\\$1/g;
# substitute ? preceded by an even number of \
- my $s = $CaptureSingle ? '(.)' : '.';
+ my $s = capture_single;
s/(?<!\\)((?:\\\\)*)\?/$1$s/g;
# substitute * preceded by an even number of \
- $s = $CaptureAny ? (($CaptureAny > 0) ? '(.*)' : '(.*?)')
- : '.*';
+ $s = capture_any;
s/(?<!\\)((?:\\\\)*)\*+/$1$s/g;
return $_;
}
+sub do_sql {
+ local $_ = shift;
+ # escape an odd number of \ that doesn't protect a regexp/wildcard special char
+ s/(?<!\\)((?:\\\\)*\\(?:[^\W_]|\s|$))/\\$1/g;
+ # substitute _ preceded by an even number of \
+ my $s = capture_single;
+ s/(?<!\\)((?:\\\\)*)_/$1$s/g;
+ # substitute * preceded by an even number of \
+ $s = capture_any;
+ s/(?<!\\)((?:\\\\)*)%+/$1$s/g;
+ return $_;
+}
+
sub do_commas {
local $_ = shift;
# substitute , preceded by an even number of \
$re .= do_commas($prefix) . do_brackets($bracket);
}
$re .= do_commas($rest);
- return ($CaptureBrackets ? '(' : '(?:') . $re . ')';
+ return capture_brackets . $re . ')';
}
sub do_bracketed {
#!perl -T
-use Test::More tests => 4;
+use Test::More tests => 5;
require Regexp::Wildcards;
-for (qw/wc2re_jokers wc2re_unix wc2re_win32 wc2re/) {
+for (qw/wc2re_jokers wc2re_sql wc2re_unix wc2re_win32 wc2re/) {
eval { Regexp::Wildcards->import($_) };
ok(!$@, 'import ' . $_);
}
use Test::More tests => 10;
-use Regexp::Wildcards qw/wc2re wc2re_unix wc2re_win32/;
+use Regexp::Wildcards qw/wc2re wc2re_win32/;
for my $O (qw/win32 dos os2 cygwin/, 'MSWin32') {
for ('a{b,c}*', 'a?{b\\{,\\}c}') {
#!perl -T
-use Test::More tests => 3 * (4 + 2 + 7 + 9 + 2) * 3;
+use Test::More tests => 4 * (4 + 2 + 7 + 9 + 2) * 3;
use Regexp::Wildcards qw/wc2re/;
sub try {
my ($t, $s, $x, $y) = @_;
$y = $x unless defined $y;
- ok(wc2re('ab' . $x, $t) eq 'ab' . $y, $s . ' (beginning)');
- ok(wc2re('a' . $x . 'b', $t) eq 'a' . $y . 'b', $s . ' (middle)');
- ok(wc2re($x . 'ab', $t) eq $y . 'ab', $s . ' (end)');
+ ok(wc2re('ab' . $x, $t) eq 'ab' . $y, $s . ' (begin) ['.$t.']');
+ ok(wc2re('a' . $x . 'b', $t) eq 'a' . $y . 'b', $s . ' (middle) ['.$t.']');
+ ok(wc2re($x . 'ab', $t) eq $y . 'ab', $s . ' (end) ['.$t.']');
}
-for my $t (qw/unix win32 jokers/) {
+sub alltests {
+ my ($t, $one, $any) = @_;
+
# Simple
- try $t, 'simple *', '*', '.*';
- try $t, 'simple ?', '?', '.';
+ try $t, "simple $any", $any, '.*';
+ try $t, "simple $one", $one, '.';
- ok(wc2re('?*ab', $t) eq '..*ab', 'simple ? and * (beginning)');
- ok(wc2re('?a*b', $t) eq '.a.*b', 'simple ? and * (middle)');
- ok(wc2re('?ab*', $t) eq '.ab.*', 'simple ? and * (end)');
+ ok(wc2re($one.$any.'ab', $t) eq '..*ab',
+ "simple $one and $any (begin) [$t]");
+ ok(wc2re($one.'a'.$any.'b', $t) eq '.a.*b',
+ "simple $one and $any (middle) [$t]");
+ ok(wc2re($one.'ab'.$any, $t) eq '.ab.*',
+ "simple $one and $any (end) [$t]");
- ok(wc2re('*ab?', $t) eq '.*ab.', 'simple * and ? (beginning)');
- ok(wc2re('a*b?', $t) eq 'a.*b.', 'simple * and ? (middle)');
- ok(wc2re('ab*?', $t) eq 'ab.*.', 'simple * and ? (end)');
+ ok(wc2re($any.'ab'.$one, $t) eq '.*ab.',
+ "simple $any and $one (begin) [$t]");
+ ok(wc2re('a'.$any.'b'.$one, $t) eq 'a.*b.',
+ "simple $any and $one (middle) [$t]");
+ ok(wc2re('ab'.$any.$one, $t) eq 'ab.*.',
+ "simple $any and $one (end) [$t]");
# Multiple
- try $t, 'multiple *', '**', '.*';
- try $t, 'multiple ?', '??', '..';
+ try $t, "multiple $any", $any x 2, '.*';
+ try $t, "multiple $one", $one x 2, '..';
# Variables
{
local $Regexp::Wildcards::CaptureSingle = 1;
- try $t, 'multiple capturing ?', '??\\??', '(.)(.)\\?(.)';
+ try $t, "multiple capturing $one", $one.$one.'\\'.$one.$one,
+ '(.)(.)\\'.$one.'(.)';
+
local $Regexp::Wildcards::CaptureAny = 1;
- try $t, 'multiple capturing * (greedy)', '**\\**', '(.*)\\*(.*)';
- try $t, 'multiple capturing * (greedy) and capturing ?',
- '**??\\??\\**', '(.*)(.)(.)\\?(.)\\*(.*)';
+ try $t, "multiple capturing $any (greedy)", $any.$any.'\\'.$any.$any,
+ '(.*)\\'.$any.'(.*)';
+ my $wc = $any.$any.$one.$one.'\\'.$one.$one.'\\'.$any.$any;
+ try $t, "multiple capturing $any (greedy) and capturing $one",
+ $wc, '(.*)(.)(.)\\'.$one.'(.)\\'.$any.'(.*)';
+
$Regexp::Wildcards::CaptureSingle = 0;
- try $t, 'multiple capturing * (greedy) and non-capturing ?',
- '**??\\??\\**', '(.*)..\\?.\\*(.*)';
+ try $t, "multiple capturing $any (greedy) and non-capturing $one",
+ $wc, '(.*)..\\'.$one.'.\\'.$any.'(.*)';
+
$Regexp::Wildcards::CaptureAny = -1;
- try $t, 'multiple capturing * (non-greedy)', '**\\**', '(.*?)\\*(.*?)';
- try $t, 'multiple capturing * (non-greedy) and non-capturing ?',
- '**??\\??\\**', '(.*?)..\\?.\\*(.*?)';
+ try $t, "multiple capturing $any (non-greedy)", $any.$any.'\\'.$any.$any,
+ '(.*?)\\'.$any.'(.*?)';
+ try $t, "multiple capturing $any (non-greedy) and non-capturing $one",
+ $wc, '(.*?)..\\'.$one.'.\\'.$any.'(.*?)';
+
$Regexp::Wildcards::CaptureSingle = 1;
- try $t, 'multiple capturing * (non-greedy) and capturing ?',
- '**??\\??\\**', '(.*?)(.)(.)\\?(.)\\*(.*?)';
+ try $t, "multiple capturing $any (non-greedy) and capturing $one",
+ $wc, '(.*?)(.)(.)\\'.$one.'(.)\\'.$any.'(.*?)';
}
# Escaping
- try $t, 'escaping *', '\\*';
- try $t, 'escaping *', '\\?';
- try $t, 'escaping \\\\\\*', '\\\\\\*';
- try $t, 'escaping \\\\\\?', '\\\\\\?';
+ try $t, "escaping $any", '\\'.$any;
+ try $t, "escaping $one", '\\'.$one;
+ try $t, "escaping \\\\\\$any", '\\\\\\'.$any;
+ try $t, "escaping \\\\\\$one", '\\\\\\'.$one;
- try $t, 'not escaping \\\\*', '\\\\*', '\\\\.*';
- try $t, 'not escaping \\\\?', '\\\\?', '\\\\.';
+ try $t, "not escaping \\\\$any", '\\\\'.$any, '\\\\.*';
+ try $t, "not escaping \\\\$one", '\\\\'.$one, '\\\\.';
try $t, 'escaping \\', '\\', '\\\\';
try $t, 'escaping regex characters', '[]', '\\[\\]';
# Mixed
- try $t, 'mixed * and \\*', '*\\**', '.*\\*.*';
- try $t, 'mixed ? and \\?', '?\\??', '.\\?.';
+ try $t, "mixed $any and \\$any", $any.'\\'.$any.$any, '.*\\'.$any.'.*';
+ try $t, "mixed $one and \\$one", $one.'\\'.$one.$one, '.\\'.$one.'.';
}
+
+alltests $_, '?', '*' for qw/jokers unix win32/;
+alltests 'sql', '_', '%';
#!perl -T
-use Test::More tests => 26;
+use Test::More tests => 27;
-use Regexp::Wildcards qw/wc2re_jokers wc2re_unix wc2re_win32/;
+use Regexp::Wildcards qw/wc2re_jokers wc2re_sql wc2re_unix wc2re_win32/;
ok(wc2re_jokers('a{b\\\\,c\\\\}d') eq 'a\\{b\\\\\\,c\\\\\\}d', 'wc2re_jokers');
+ok(wc2re_sql('a{b\\\\,c\\\\}d') eq 'a\\{b\\\\\\,c\\\\\\}d', 'wc2re_sql');
+
ok(wc2re_win32('a{b\\\\,c\\\\}d') eq '(?:a\\{b\\\\|c\\\\\\}d)', 'wc2re_win32');
ok(wc2re_unix('{}') eq '(?:)', 'empty brackets');
use Test::More;
eval "use Test::Pod::Coverage 1.04";
plan skip_all => "Test::Pod::Coverage 1.04 required for testing POD coverage" if $@;
-all_pod_coverage_ok( { also_private => [ qr/^do_/, qw/extract/ ] } );
+all_pod_coverage_ok( {
+ also_private => [ qr/^do_/, qr/^capture_/, qw/extract/ ]
+} );