]> git.vpit.fr Git - perl/modules/Regexp-Wildcards.git/blob - README
Importing Regexp-Wildcards-0.02.tar.gz
[perl/modules/Regexp-Wildcards.git] / README
1 NAME
2     Regexp::Wildcards - Converts wildcards expressions to Perl regular
3     expressions.
4
5 VERSION
6     Version 0.02
7
8 SYNOPSIS
9         use Regexp::Wildcards qw/wc2re/;
10
11         my $re;
12         $re = wc2re 'a{b.,c}*' => 'unix';   # Do it Unix style.
13         $re = wc2re 'a.,b*'    => 'win32';  # Do it Windows style.
14         $re = wc2re '*{x,y}.'  => 'jokers'; # Process the jokers & escape the rest.
15
16 DESCRIPTION
17     In many situations, users may want to specify patterns to match but
18     don't need the full power of regexps. Wildcards make one of those sets
19     of simplified rules. This module converts wildcards expressions to Perl
20     regular expressions, so that you can use them for matching. It handles
21     the "*" and "?" jokers, as well as Unix bracketed alternatives "{,}",
22     and uses the backspace ("\") as an escape character. Wrappers are
23     provided to mimic the behaviour of Windows and Unix shells.
24
25 EXPORT
26     Four functions are exported only on request : "wc2re", "wc2re_unix",
27     "wc2re_win32" and "wc2re_jokers".
28
29 FUNCTIONS
30   "wc2re_unix"
31     This function takes as its only argument the wildcard string to process,
32     and returns the corresponding regular expression according to standard
33     Unix wildcard rules. It successively escapes all unprotected regexp
34     special characters that doesn't hold any meaning for wildcards, turns
35     jokers into their regexp equivalents, and changes bracketed blocks into
36     "(?:|)" alternations. If brackets are unbalanced, it will try to
37     substitute as many of them as possible, and then escape the remaining
38     "{" and "}". Commas outside of any bracket-delimited block will also be
39     escaped.
40
41         # This is a valid brackets expression which is correctly handled.
42         print 'ok' if wc2re_unix('{a{b,c}d,e}') eq '(?:a(?:b|c)d|e)';
43
44     Unbalanced bracket expressions can always be rescued, but it may change
45     completely its meaning. For example :
46
47         # The first comma is replaced, and the remaining brackets and comma are
48         # escaped.
49         print 'ok' if wc2re_unix('{a\\{b,c}d,e}') eq '(?:a\\{b|c)d\\,e\\}';
50
51         # All the brackets and commas are escaped.
52         print 'ok' if wc2re_unix('{a{b,c\\}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
53
54   "wc2re_win32"
55     Similar to the precedent, but for Windows wildcards. Bracketed blocks
56     are no longer handled (which means that brackets will be escaped), but
57     you can provide a comma-separated list of items.
58
59         # All the brackets are escaped, and commas are seen as list delimiters.
60         print 'ok' if wc2re_win32('{a{b,c}d,e}') eq '(?:\\{a\\{b|c\\}d|e\\})';
61
62   "wc2re_jokers"
63     This one only handles the "?" and "*" jokers. All other unquoted regexp
64     metacharacters will be escaped.
65
66         # Everything is escaped.
67         print 'ok' if wc2re_jokers('{a{b,c}d,e}') eq '\\{a\\{b\\,c\\}d\\,e\\}';
68
69   "wc2re"
70     A generic function that wraps around all the different rules. The first
71     argument is the wildcard expression, and the second one is the type of
72     rules to apply, currently either "unix", "win32" or "jokers". If the
73     type is undefined, it defaults to "unix".
74
75 DEPENDENCIES
76     Text::Balanced, which is bundled with perl since version 5.7.3
77
78 SEE ALSO
79     Some modules provide incomplete alternatives as helper functions :
80
81     Net::FTPServer has a method for that. Only jokers are translated, and
82     escaping won't preserve them.
83
84     File::Find::Match::Util has a "wildcar" function that compiles a
85     matcher. Only handles "*".
86
87     Text::Buffer has the "convertWildcardToRegex" class method that handles
88     jokers.
89
90 AUTHOR
91     Vincent Pit, "<perl at profvince.com>"
92
93 BUGS
94     Please report any bugs or feature requests to "bug-regexp-wildcards at
95     rt.cpan.org", or through the web interface at
96     <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Regexp-Wildcards>. I
97     will be notified, and then you'll automatically be notified of progress
98     on your bug as I make changes.
99
100 SUPPORT
101     You can find documentation for this module with the perldoc command.
102
103         perldoc Regexp::Wildcards
104
105 COPYRIGHT & LICENSE
106     Copyright 2007 Vincent Pit, all rights reserved.
107
108     This program is free software; you can redistribute it and/or modify it
109     under the same terms as Perl itself.
110