]> git.vpit.fr Git - perl/modules/Regexp-Wildcards.git/blobdiff - README
Importing Regexp-Wildcards-0.06.tar.gz
[perl/modules/Regexp-Wildcards.git] / README
diff --git a/README b/README
index 5f2233248e79ddb511d94594d23d116eca4edf9d..0780e9ad50822c23df7cdb81f640ba0059a94915 100644 (file)
--- a/README
+++ b/README
@@ -3,7 +3,7 @@ NAME
     expressions.
 
 VERSION
-    Version 0.05
+    Version 0.06
 
 SYNOPSIS
         use Regexp::Wildcards qw/wc2re/;
@@ -12,28 +12,30 @@ 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.
 
 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
@@ -42,23 +44,36 @@ VARIABLES
     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
@@ -71,19 +86,24 @@ FUNCTIONS
   "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.
@@ -101,7 +121,7 @@ FUNCTIONS
         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.
 
@@ -113,9 +133,10 @@ FUNCTIONS
     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
@@ -131,9 +152,9 @@ FUNCTIONS
          $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