.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Regexp::Wildcards 3pm" .TH Regexp::Wildcards 3pm "2018-11-15" "perl v5.28.0" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Regexp::Wildcards \- Converts wildcard expressions to Perl regular expressions. .SH "VERSION" .IX Header "VERSION" Version 1.05 .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Regexp::Wildcards; \& \& my $rw = Regexp::Wildcards\->new(type => \*(Aqunix\*(Aq); \& \& my $re; \& $re = $rw\->convert(\*(Aqa{b?,c}*\*(Aq); # Do it Unix shell style. \& $re = $rw\->convert(\*(Aqa?,b*\*(Aq, \*(Aqwin32\*(Aq); # Do it Windows shell style. \& $re = $rw\->convert(\*(Aq*{x,y}?\*(Aq, \*(Aqjokers\*(Aq); # Process the jokers and \& # escape the rest. \& $re = $rw\->convert(\*(Aq%a_c%\*(Aq, \*(Aqsql\*(Aq); # Turn SQL wildcards into \& # regexps. \& \& $rw = Regexp::Wildcards\->new( \& do => [ qw ], # Do jokers and brackets. \& capture => [ qw ], # Capture *\*(Aqs greedily. \& ); \& \& $rw\->do(add => \*(Aqgroups\*(Aq); # Don\*(Aqt escape groups. \& $rw\->capture(rem => [ qw ]); # Actually we want non\-greedy \& # matches. \& $re = $rw\->convert(\*(Aq*a{,(b)?}?c*\*(Aq); # \*(Aq(.*?)a(?:|(b).).c(.*?)\*(Aq \& $rw\->capture(); # No more captures. .Ve .SH "DESCRIPTION" .IX Header "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. .PP It handles the \f(CW\*(C`*\*(C'\fR and \f(CW\*(C`?\*(C'\fR wildcards, as well as Unix bracketed alternatives \f(CW\*(C`{,}\*(C'\fR, but also \f(CW\*(C`%\*(C'\fR and \f(CW\*(C`_\*(C'\fR \s-1SQL\s0 wildcards. If required, it can also keep original \f(CW\*(C`(...)\*(C'\fR groups or \f(CW\*(C`^\*(C'\fR and \f(CW\*(C`$\*(C'\fR anchors. Backslash (\f(CW\*(C`\e\*(C'\fR) is used as an escape character. .PP Typesets that mimic the behaviour of Windows and Unix shells are also provided. .SH "METHODS" .IX Header "METHODS" .ie n .SS """new""" .el .SS "\f(CWnew\fP" .IX Subsection "new" .Vb 2 \& my $rw = Regexp::Wildcards\->new(do => $what, capture => $capture); \& my $rw = Regexp::Wildcards\->new(type => $type, capture => $capture); .Ve .PP Constructs a new Regexp::Wildcard object. .PP \&\f(CW\*(C`do\*(C'\fR lists all features that should be enabled when converting wildcards to regexps. Refer to \*(L"do\*(R" for details on what can be passed in \f(CW$what\fR. .PP The \f(CW\*(C`type\*(C'\fR specifies a predefined set of \f(CW\*(C`do\*(C'\fR features to use. See \*(L"type\*(R" for details on which types are valid. The \f(CW\*(C`do\*(C'\fR option overrides \f(CW\*(C`type\*(C'\fR. .PP \&\f(CW\*(C`capture\*(C'\fR lists which atoms should be capturing. Refer to \*(L"capture\*(R" for more details. .ie n .SS """do""" .el .SS "\f(CWdo\fP" .IX Subsection "do" .Vb 4 \& $rw\->do($what); \& $rw\->do(set => $c1); \& $rw\->do(add => $c2); \& $rw\->do(rem => $c3); .Ve .PP Specifies the list of metacharacters to convert or to prevent for escaping. They fit into six classes : .IP "\(bu" 4 \&\f(CW\*(Aqjokers\*(Aq\fR .Sp Converts \f(CW\*(C`?\*(C'\fR to \f(CW\*(C`.\*(C'\fR and \f(CW\*(C`*\*(C'\fR to \f(CW\*(C`.*\*(C'\fR. .Sp .Vb 1 \& \*(Aqa**\e\e*b??\e\e?c\*(Aq ==> \*(Aqa.*\e\e*b..\e\e?c\*(Aq .Ve .IP "\(bu" 4 \&\f(CW\*(Aqsql\*(Aq\fR .Sp Converts \f(CW\*(C`_\*(C'\fR to \f(CW\*(C`.\*(C'\fR and \f(CW\*(C`%\*(C'\fR to \f(CW\*(C`.*\*(C'\fR. .Sp .Vb 1 \& \*(Aqa%%\e\e%b_\|_\e\e_c\*(Aq ==> \*(Aqa.*\e\e%b..\e\e_c\*(Aq .Ve .IP "\(bu" 4 \&\f(CW\*(Aqcommas\*(Aq\fR .Sp Converts all \f(CW\*(C`,\*(C'\fR to \f(CW\*(C`|\*(C'\fR and puts the complete resulting regular expression inside \f(CW\*(C`(?: ... )\*(C'\fR. .Sp .Vb 1 \& \*(Aqa,b{c,d},e\*(Aq ==> \*(Aq(?:a|b\e\e{c|d\e\e}|e)\*(Aq .Ve .IP "\(bu" 4 \&\f(CW\*(Aqbrackets\*(Aq\fR .Sp Converts all matching \f(CW\*(C`{ ... , ... }\*(C'\fR brackets to \f(CW\*(C`(?: ... | ... )\*(C'\fR alternations. If some brackets are unbalanced, it tries to substitute as many of them as possible, and then escape the remaining unmatched \f(CW\*(C`{\*(C'\fR and \f(CW\*(C`}\*(C'\fR. Commas outside of any bracket-delimited block are also escaped. .Sp .Vb 3 \& \*(Aqa,b{c,d},e\*(Aq ==> \*(Aqa\e\e,b(?:c|d)\e\e,e\*(Aq \& \*(Aq{a\e\e{b,c}d,e}\*(Aq ==> \*(Aq(?:a\e\e{b|c)d\e\e,e\e\e}\*(Aq \& \*(Aq{a{b,c\e\e}d,e}\*(Aq ==> \*(Aq\e\e{a\e\e{b\e\e,c\e\e}d\e\e,e\e\e}\*(Aq .Ve .IP "\(bu" 4 \&\f(CW\*(Aqgroups\*(Aq\fR .Sp Keeps the parenthesis \f(CW\*(C`( ... )\*(C'\fR of the original string without escaping them. Currently, no check is done to ensure that the parenthesis are matching. .Sp .Vb 1 \& \*(Aqa(b(c))d\e\e(\e\e)\*(Aq ==> (no change) .Ve .IP "\(bu" 4 \&\f(CW\*(Aqanchors\*(Aq\fR .Sp Prevents the \fIbeginning-of-line\fR \f(CW\*(C`^\*(C'\fR and \fIend-of-line\fR \f(CW\*(C`$\*(C'\fR anchors to be escaped. Since \f(CW\*(C`[...]\*(C'\fR character class are currently escaped, a \f(CW\*(C`^\*(C'\fR will always be interpreted as \fIbeginning-of-line\fR. .Sp .Vb 1 \& \*(Aqa^b$c\*(Aq ==> (no change) .Ve .PP Each \f(CW$c\fR can be any of : .IP "\(bu" 4 A hash reference, with wanted metacharacter group names (described above) as keys and booleans as values ; .IP "\(bu" 4 An array reference containing the list of wanted metacharacter classes ; .IP "\(bu" 4 A plain scalar, when only one group is required. .PP When \f(CW\*(C`set\*(C'\fR is present, the classes given as its value replace the current object options. Then the \f(CW\*(C`add\*(C'\fR classes are added, and the \f(CW\*(C`rem\*(C'\fR classes removed. .PP Passing a sole scalar \f(CW$what\fR is equivalent as passing \f(CW\*(C`set => $what\*(C'\fR. No argument means \f(CW\*(C`set => [ ]\*(C'\fR. .PP .Vb 6 \& $rw\->do(set => \*(Aqjokers\*(Aq); # Only translate jokers. \& $rw\->do(\*(Aqjokers\*(Aq); # Same. \& $rw\->do(add => [ qw ]); # Translate also SQL and commas. \& $rw\->do(rem => \*(Aqjokers\*(Aq); # Specifying both \*(Aqsql\*(Aq and \& # \*(Aqjokers\*(Aq is useless. \& $rw\->do(); # Translate nothing. .Ve .PP The \f(CW\*(C`do\*(C'\fR method returns the Regexp::Wildcards object. .ie n .SS """type""" .el .SS "\f(CWtype\fP" .IX Subsection "type" .Vb 1 \& $rw\->type($type); .Ve .PP Notifies to convert the metacharacters that corresponds to the predefined type \f(CW$type\fR. \&\f(CW$type\fR can be any of : .IP "\(bu" 4 \&\f(CW\*(Aqjokers\*(Aq\fR, \f(CW\*(Aqsql\*(Aq\fR, \f(CW\*(Aqcommas\*(Aq\fR, \f(CW\*(Aqbrackets\*(Aq\fR .Sp Singleton types that enable the corresponding \f(CW\*(C`do\*(C'\fR classes. .IP "\(bu" 4 \&\f(CW\*(Aqunix\*(Aq\fR .Sp Covers typical Unix shell globbing features (effectively \f(CW\*(Aqjokers\*(Aq\fR and \f(CW\*(Aqbrackets\*(Aq\fR). .IP "\(bu" 4 \&\f(CW$^O\fR values for common Unix systems .Sp Wrap to \f(CW\*(Aqunix\*(Aq\fR (see perlport for the list). .IP "\(bu" 4 \&\f(CW\*(C`undef\*(C'\fR .Sp Defaults to \f(CW\*(Aqunix\*(Aq\fR. .IP "\(bu" 4 \&\f(CW\*(Aqwin32\*(Aq\fR .Sp Covers typical Windows shell globbing features (effectively \f(CW\*(Aqjokers\*(Aq\fR and \f(CW\*(Aqcommas\*(Aq\fR). .IP "\(bu" 4 \&\f(CW\*(Aqdos\*(Aq\fR, \f(CW\*(Aqos2\*(Aq\fR, \f(CW\*(AqMSWin32\*(Aq\fR, \f(CW\*(Aqcygwin\*(Aq\fR .Sp Wrap to \f(CW\*(Aqwin32\*(Aq\fR. .PP In particular, you can usually pass \f(CW$^O\fR as the \f(CW$type\fR and get the corresponding shell behaviour. .PP .Vb 3 \& $rw\->type(\*(Aqwin32\*(Aq); # Set type to win32. \& $rw\->type($^O); # Set type to unix on Unices and win32 on Windows \& $rw\->type(); # Set type to unix. .Ve .PP The \f(CW\*(C`type\*(C'\fR method returns the Regexp::Wildcards object. .ie n .SS """capture""" .el .SS "\f(CWcapture\fP" .IX Subsection "capture" .Vb 4 \& $rw\->capture($captures); \& $rw\->capture(set => $c1); \& $rw\->capture(add => $c2); \& $rw\->capture(rem => $c3); .Ve .PP Specifies the list of atoms to capture. This method works like \*(L"do\*(R", except that the classes are different : .IP "\(bu" 4 \&\f(CW\*(Aqsingle\*(Aq\fR .Sp Captures all unescaped \fI\*(L"exactly one\*(R"\fR metacharacters, i.e. \f(CW\*(C`?\*(C'\fR for wildcards or \f(CW\*(C`_\*(C'\fR for \s-1SQL.\s0 .Sp .Vb 2 \& \*(Aqa???b\e\e??\*(Aq ==> \*(Aqa(.)(.)(.)b\e\e?(.)\*(Aq \& \*(Aqa_\|_\|_b\e\e_\|_\*(Aq ==> \*(Aqa(.)(.)(.)b\e\e_(.)\*(Aq .Ve .IP "\(bu" 4 \&\f(CW\*(Aqany\*(Aq\fR .Sp Captures all unescaped \fI\*(L"any\*(R"\fR metacharacters, i.e. \f(CW\*(C`*\*(C'\fR for wildcards or \f(CW\*(C`%\*(C'\fR for \s-1SQL.\s0 .Sp .Vb 2 \& \*(Aqa***b\e\e**\*(Aq ==> \*(Aqa(.*)b\e\e*(.*)\*(Aq \& \*(Aqa%%%b\e\e%%\*(Aq ==> \*(Aqa(.*)b\e\e%(.*)\*(Aq .Ve .IP "\(bu" 4 \&\f(CW\*(Aqgreedy\*(Aq\fR .Sp When used in conjunction with \f(CW\*(Aqany\*(Aq\fR, it makes the \f(CW\*(Aqany\*(Aq\fR captures greedy (by default they are not). .Sp .Vb 2 \& \*(Aqa***b\e\e**\*(Aq ==> \*(Aqa(.*?)b\e\e*(.*?)\*(Aq \& \*(Aqa%%%b\e\e%%\*(Aq ==> \*(Aqa(.*?)b\e\e%(.*?)\*(Aq .Ve .IP "\(bu" 4 \&\f(CW\*(Aqbrackets\*(Aq\fR .Sp Capture matching \f(CW\*(C`{ ... , ... }\*(C'\fR alternations. .Sp .Vb 1 \& \*(Aqa{b\e\e},\e\e{c}\*(Aq ==> \*(Aqa(b\e\e}|\e\e{c)\*(Aq .Ve .PP .Vb 7 \& $rw\->capture(set => \*(Aqsingle\*(Aq); # Only capture "exactly one" \& # metacharacters. \& $rw\->capture(\*(Aqsingle\*(Aq); # Same. \& $rw\->capture(add => [ qw ]); # Also greedily capture \& # "any" metacharacters. \& $rw\->capture(rem => \*(Aqgreedy\*(Aq); # No more greed please. \& $rw\->capture(); # Capture nothing. .Ve .PP The \f(CW\*(C`capture\*(C'\fR method returns the Regexp::Wildcards object. .ie n .SS """convert""" .el .SS "\f(CWconvert\fP" .IX Subsection "convert" .Vb 2 \& my $rx = $rw\->convert($wc); \& my $rx = $rw\->convert($wc, $type); .Ve .PP Converts the wildcard expression \f(CW$wc\fR into a regular expression according to the options stored into the Regexp::Wildcards object, or to \f(CW$type\fR if it's supplied. It successively escapes all unprotected regexp special characters that doesn't hold any meaning for wildcards, then replace \f(CW\*(Aqjokers\*(Aq\fR, \f(CW\*(Aqsql\*(Aq\fR and \f(CW\*(Aqcommas\*(Aq\fR or \f(CW\*(Aqbrackets\*(Aq\fR (depending on the \*(L"do\*(R" or \*(L"type\*(R" options), all of this by applying the \f(CW\*(Aqcapture\*(Aq\fR rules specified in the constructor or by \*(L"capture\*(R". .SH "EXPORT" .IX Header "EXPORT" An object module shouldn't export any function, and so does this one. .SH "DEPENDENCIES" .IX Header "DEPENDENCIES" Carp (core module since perl 5), Scalar::Util, Text::Balanced (since 5.7.3). .SH "CAVEATS" .IX Header "CAVEATS" This module does not implement the strange behaviours of Windows shell that result from the special handling of the three last characters (for the file extension). For example, Windows \s-1XP\s0 shell matches \f(CW*a\fR like \f(CW\*(C`.*a\*(C'\fR, \f(CW\*(C`*a?\*(C'\fR like \f(CW\*(C`.*a.?\*(C'\fR, \f(CW\*(C`*a??\*(C'\fR like \f(CW\*(C`.*a.{0,2}\*(C'\fR and so on. .SH "SEE ALSO" .IX Header "SEE ALSO" Text::Glob. .SH "AUTHOR" .IX Header "AUTHOR" Vincent Pit, \f(CW\*(C`\*(C'\fR, . .PP You can contact me by mail or on \f(CW\*(C`irc.perl.org\*(C'\fR (vincent). .SH "BUGS" .IX Header "BUGS" Please report any bugs or feature requests to \f(CW\*(C`bug\-regexp\-wildcards at rt.cpan.org\*(C'\fR, or through the web interface at . I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. .SH "SUPPORT" .IX Header "SUPPORT" You can find documentation for this module with the perldoc command. .PP .Vb 1 \& perldoc Regexp::Wildcards .Ve .PP Tests code coverage report is available at . .SH "COPYRIGHT & LICENSE" .IX Header "COPYRIGHT & LICENSE" Copyright 2007,2008,2009,2013 Vincent Pit, all rights reserved. .PP This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.