Sophie

Sophie

distrib > Fedora > 15 > i386 > by-pkgid > 4fccfe23f6486142b4197d1daac0cf21 > files > 113

Falcon-doc-0.9.6.6-2.fc15.noarch.rpm

<html>
<head>
   <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
   <title>Class Regex - Class Regex</title>
   <link href="faldoc.css" rel="stylesheet" type="text/css"/>
   <link href="tabs.css" rel="stylesheet" type="text/css"/>
</head>
<body class="faldoc_body">
<div class="navitop">
   <div class="tabs">
      <ul>
         <li><a href="./index.html"><span>Main</span></a></li>
         <li><a href="./modules.html"><span>Modules</span></a></li>
         <li><a href="./pages.html"><span>Related pages</span></a></li>
         <li><a href="./groups.html"><span>Groups</span></a></li>
         <li><a href="./classes.html"><span>Classes</span></a></li>
         <li><a href="./objects.html"><span>Objects</span></a></li>
         <li><a href="./functions.html"><span>All functions</span></a></li>
         <li><a href="./enum.html"><span>Enumerations</span></a></li>
         
      </ul>
   </div>
</div>
<hr/>

<h1 class="faldoc_title">Class Regex<span class="faldoc_belong"><a href="./module_feather_regex.html">[in Regular Expression]</a></p></h1>

<p class="faldoc_brief">Regular expression binding encapsulation. </p>
<p class="faldoc_funcdecl">
<b>class</b> Regex( pattern, [options] )
</p>


   <p class="faldoc_brief"><a href="#more">more...</a></p>
   <h2 class="faldoc_title">Summary</h2>
   <table class="faldoc_list">
   
      
         <tr><td><a href="#captured">captured()</a></td><td>Return one of the captured (parenthesized) expressions. </td></tr>
      
         <tr><td><a href="#capturedCount">capturedCount()</a></td><td>Return the count of captured (parenthesized) expressions. </td></tr>
      
         <tr><td><a href="#compare">compare()</a></td><td>Checks if a given strings can be matched by this expression. </td></tr>
      
         <tr><td><a href="#find">find()</a></td><td>Finds a range matching this regular expression in a string. </td></tr>
      
         <tr><td><a href="#findAll">findAll()</a></td><td>Find all ranges where this regular expression can mach the string. </td></tr>
      
         <tr><td><a href="#findAllOverlapped">findAllOverlapped()</a></td><td>Find all ranges where this regular expression can mach the string, with possibly overlapped matches. </td></tr>
      
         <tr><td><a href="#grab">grab()</a></td><td>Returns the part of a target string matched by this regular expression. </td></tr>
      
         <tr><td><a href="#match">match()</a></td><td>Matches this regular expression against a string. </td></tr>
      
         <tr><td><a href="#replace">replace()</a></td><td>Replace a substring matching this regular expression with another string. </td></tr>
      
         <tr><td><a href="#replaceAll">replaceAll()</a></td><td>Replaces all the possible matches of this regular expression in a target with a given string. </td></tr>
      
         <tr><td><a href="#split">split()</a></td><td>Splits a string at match points. </td></tr>
      
         <tr><td><a href="#study">study()</a></td><td>Study the pattern after compilation. </td></tr>
      
         <tr><td><a href="#subst">subst()</a></td><td>Replaces all the matches expanding placeholders. </td></tr>
      
         <tr><td><a href="#version">version()</a></td><td>Returns the PCRE version used by this binding. </td></tr>
      
   
   </table>







<a name="more"><h2 class="faldoc_title">Detailed description</h2></a>

<p class="faldoc_funcdecl">
<b>class</b> Regex( pattern, [options] )
</p>
<table class="faldoc_function">
<tr><td class="faldoc_param">pattern</td><td class="faldoc_paramdesc">The regular expression pattern to be compiled. </td></tr>
<tr><td class="faldoc_optparam">options</td><td class="faldoc_optparamdesc">Pattern compilation options. </td></tr>
</table>
<br/>
<p class="item_brief">Regular expression binding encapsulation. </p>
<p class="faldoc_text">The class constructor creates a Regex instance that can be then used to match, find, extract  and substitute strings. Compilation of regular expressions can be an heavy step, so it's better to do it once and for all. In a program using repeatedly a set of well defined patterns, an option worth being considered is that of creating object instances that will have the VM to compile the pattern in the link step: </p>
<pre class="faldoc_code">
 load regex

object bigPattern from Regex( "A pattern (.*) to be compiled" )
   // we may eventually consider also a study step in init
   init
      self.study()
   end
end

//...
if bigPattern.match( "a string" )
   ...
end
</pre>
<p class="faldoc_text">In case of regular expression pattern error, a RegexError instance will be raised. The option parameter can be provided to pass pattern compilation options to the constructor. It generally follows the PERL regular expression parameter specification, so  that: </p>
<pre class="faldoc_code">
 PERL: /a pattern/i
Falcon: Regex( "a pattern", "i" )
</pre>
<p class="faldoc_text">The recognized options are (case sensitive): </p>
<ul>
<li><b>a</b>: anchored pattern. Usually, if only part of a pattern matches, a new search is attempted in the rest of the string. When this option is set, the pattern must either match completely or be rejected as the first match begins. So, the pattern "abc" will usually match "abdabc" starting from character 3, but if anchored option is set it won't match, as "abc" will start to match at the beginning of string, but then will fail when "d" is met. </li><li><b>i</b>: ignore case while matching. Case ignoring is currently supported only for Unicode characters below 128; this means that accented latin case ignoring is not supported. For example, "è" and "È" won't match even if "i" option is set. </li><li><b>m</b>: multiline match. Usually, the special characters "^" and "$" matches respectively the begin and the end of the string, so that "^pattern$" will match only "pattern", and not "this is a pattern". With "m" option, "^" and "$" matches the begin and the end of a line, being lines separated by Falcon newline characters ("\n"). </li><li><b>s</b>: dot match all. Usually, the line separator "\n" is not captured in wide parenthesized expressions as (.*), and the generic "any character" wildcard (the dot ".") doesn't matches it. With "s" option, "\n" is considered as a normal character and included in matches (although this doesn't alter the behavior of "^" and "$" which are controlled by the "m" option). </li><li><b>f</b>: first line. Match must start before or at the first "\n", or else it will fail. </li><li><b>g</b>: ungreedy match. Repetition patterns behave normally in a way that is defined "greedy", unless followed by a question mark. Greedy matching will force quantifiers to match as many characters as possible in the target string. For example, normally 'field:\s*(.*);', if applied to a string with two ";" after "field" will return the longest possible match. If applied to "field: a; b; c; and the rest" would return "a; b; c" as first submatch. Using a question mark would force to match the shortest alternative: 'field:\s*(.*?);' would return only "a" as first submatch. The "g" option inverts this behavior, so that repetition quantifiers are ungreedy by default, and "?" will make them greedy. </li><li><b>S</b>: study the pattern. Tells Regex constructor to perform also a study step after compilation. According to PCRE documentation, this has currently little utility except for some very complex pattern involving recursive searches. </li>
</ul>
<p class="faldoc_text"> In case of error in compilation of the pattern (or eventually in the study step, if required), the constructor will raise an error of class <a href="./class_RegexError.html">RegexError</a>. </p>




   <h2 class="faldoc_title">Methods</h2>
   
      <h3 class="faldoc_funcname"><a name="captured">captured()</a></h3>
      <p class="item_brief">Return one of the captured (parenthesized) expressions. </p>
      <p class="faldoc_funcdecl">Regex.captured( count )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">count</td><td class="faldoc_paramdesc">Id of the captured substring, starting from 1; 0 represents all the matched string. </td></tr>
         
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">A range defining a captured match. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This method returns one of the match ranges that has been determined by the last match, find or replace operation. If 0 is passed as count parameter, the whole match range is returned; each parenthesized expression match range can be retrieved passing 1 or above as count parameter. The order of parenthesized expression is given considering the first parenthesis. The returned value is a closed range describing the area where the capture had effect in the target string. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="capturedCount">capturedCount()</a></h3>
      <p class="item_brief">Return the count of captured (parenthesized) expressions. </p>
      <p class="faldoc_funcdecl">Regex.capturedCount( )</p>
      
         <table class="faldoc_function">
         
         
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">Count of captured subranges. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This method returns available number of captured ranges after a successful match. This number is the amount of parenthesized expressions in the regular expression plus one. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="compare">compare()</a></h3>
      <p class="item_brief">Checks if a given strings can be matched by this expression. </p>
      <p class="faldoc_funcdecl">Regex.compare( string )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">A string. </td></tr>
         
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">0 if the string is matched by the regex pattern. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This method overloads the BOM compare method, so that this Regex instance can be used in direct comparations. Switch tests and equality tests will succeed if the pattern matches agains the given string. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="find">find()</a></h3>
      <p class="item_brief">Finds a range matching this regular expression in a string. </p>
      <p class="faldoc_funcdecl">Regex.find( string, [start] )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">A string in which the pattern has to be found. </td></tr>
         <tr><td class="faldoc_optparam">start</td><td class="faldoc_optparamdesc">An optional starting point in the string. </td></tr>
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">A range where the pattern matches, or nil. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This function works as the method match(), but on success it immediately returns the range containing the area in the string parameter where the pattern has matched. Also, this function can be provided with an optional start parameter that can be used to begin the search for the pattern from an arbitrary point in the string. </p>
<p class="faldoc_text">Finds the first occourence of the pattern in the string. The returned ranged may be applied to the string in order to extract the desired substring. </p>
<p class="faldoc_text">If the pattern doesn't matches, returns nil. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="findAll">findAll()</a></h3>
      <p class="item_brief">Find all ranges where this regular expression can mach the string. </p>
      <p class="faldoc_funcdecl">Regex.findAll( string, [start], [maxcount] )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">String where to scan for the pattern. </td></tr>
         <tr><td class="faldoc_optparam">start</td><td class="faldoc_optparamdesc">Optional start position in the string. </td></tr><tr><td class="faldoc_optparam">maxcount</td><td class="faldoc_optparamdesc">Optional maximum matches allowed . </td></tr>
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">A vector of ranges where the pattern matches, or nil. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This function returns an array containing all the ranges where the pattern has matched; if the pattern could not match the string, an empty array is returned. </p>
<p class="faldoc_text">This method only returns the whole match, ignoring parenthesized expressions. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="findAllOverlapped">findAllOverlapped()</a></h3>
      <p class="item_brief">Find all ranges where this regular expression can mach the string, with possibly overlapped matches. </p>
      <p class="faldoc_funcdecl">Regex.findAllOverlapped( string, [start], [maxcount] )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">String where to scan for the pattern. </td></tr>
         <tr><td class="faldoc_optparam">start</td><td class="faldoc_optparamdesc">Optional start position in the string. </td></tr><tr><td class="faldoc_optparam">maxcount</td><td class="faldoc_optparamdesc">Optional maximum matches allowed . </td></tr>
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">A vector of ranges where the pattern matches, or nil. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This function returns an array containing all the ranges where the pattern has matched; if the pattern could not match the string, an empty array is returned. </p>
<p class="faldoc_text">This method only returns the whole match, ignoring parenthesized expressions. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="grab">grab()</a></h3>
      <p class="item_brief">Returns the part of a target string matched by this regular expression. </p>
      <p class="faldoc_funcdecl">Regex.grab( string )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">String where to scan for the pattern. </td></tr>
         
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">The matching substring, or nil if the pattern doesn't match the string. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">Searches for the pattern and stores all the captured subexpressions in an array that is then returned. If the match is negative, returns nil. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="match">match()</a></h3>
      <p class="item_brief">Matches this regular expression against a string. </p>
      <p class="faldoc_funcdecl">Regex.match( string )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">String where to scan for the pattern. </td></tr>
         
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">True if the string is matched by the pattern, false otherwise. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This method searches for the pattern in the string given as parameter. If the match is successful, the method returns true. The match point can then be retrieved using the captured(0) method. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="replace">replace()</a></h3>
      <p class="item_brief">Replace a substring matching this regular expression with another string. </p>
      <p class="faldoc_funcdecl">Regex.replace( string, replacer, [start] )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">String where to scan for the pattern. </td></tr><tr><td class="faldoc_param">replacer</td><td class="faldoc_paramdesc">The string to replace the matched pattern with. </td></tr>
         <tr><td class="faldoc_optparam">start</td><td class="faldoc_optparamdesc">Optional initial scan position. </td></tr>
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">The string with the matching content replaced. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This method scans for the pattern in string, and if it's found, it is replaced with the string in the replacer parameter. The original string is untouched, and a new copy with the replaced value is returned. If the pattern can't match string, nil is returned. An optional start parameter can be given to begin the search for the pattern in string from a given position. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="replaceAll">replaceAll()</a></h3>
      <p class="item_brief">Replaces all the possible matches of this regular expression in a target with a given string. </p>
      <p class="faldoc_funcdecl">Regex.replaceAll( string, replacer )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">String where to scan for the pattern. </td></tr><tr><td class="faldoc_param">replacer</td><td class="faldoc_paramdesc">The string to replace the matched pattern with. </td></tr>
         
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">The string with the matching content replaced, or nil if no change is perfomed. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This method replaces all the occurrences of the pattern in string with the replacer parameter. If a change can be performed, a modified instance of string is returned, else nil is returned. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="split">split()</a></h3>
      <p class="item_brief">Splits a string at match points. </p>
      <p class="faldoc_funcdecl">Regex.split( string, [count], [getoken] )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">The string to be split. </td></tr>
         <tr><td class="faldoc_optparam">count</td><td class="faldoc_optparamdesc">Maximum number of split instances. </td></tr><tr><td class="faldoc_optparam">getoken</td><td class="faldoc_optparamdesc">Return also the found token. </td></tr>
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">An array containing the string slices, or nil. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">If the pattern matches the string, the part before the match is isolated. The operation is iteratively performed until the match can't be found anymore; at that point, the last string is returned. </p>
<p class="faldoc_text"> If <b>gettoken</b> parameter is given and true, the found match is inserted between the isolated strings. </p>
<p class="faldoc_text"> If <b>count</b> is given, a maximum number of matches is performed, then the array of split entities is returned. Notice that the this doesn't count tokens returned if the <b>gettoken</b> option is specified. </p>
<p class="faldoc_text">If the pattern doesn't matches, this method returns nil. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="study">study()</a></h3>
      <p class="item_brief">Study the pattern after compilation. </p>
      <p class="faldoc_funcdecl">Regex.study( )</p>
      
      <p class="faldoc_text"><p class="faldoc_text">It perform an extra compilation step; PCRE 7.6 manual suggests that this is useful only with recursive pattern. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="subst">subst()</a></h3>
      <p class="item_brief">Replaces all the matches expanding placeholders. </p>
      <p class="faldoc_funcdecl">Regex.subst( string, replacer )</p>
      
         <table class="faldoc_function">
         <tr><td class="faldoc_param">string</td><td class="faldoc_paramdesc">String where to scan for the pattern. </td></tr><tr><td class="faldoc_param">replacer</td><td class="faldoc_paramdesc">The string to replace the matched pattern with. </td></tr>
         
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">The string with the matching content replaced, or nil if no change is perfomed. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text"> This method works exacly like <a href="./class_Regex.html#replaceAll">Regex.replaceAll</a>, but it expands backslash placeholders with captured expressions. Each captured expression can be addressed via standard substitution backslashes (\0 is the whole expression, \1 is the first captured  expression, \2 the second and so on).  </p>
<pre class="faldoc_code">
 load regex

r = Regex("a([0-9]+)b")
&gt; r.subst( 'a100b', 'Number was \1.' )
</pre>
<p class="faldoc_note"><span class="faldoc_notetype">Note:</span> Remember to use double backslash on double quoted strings. </p>
</p>
   
      <h3 class="faldoc_funcname"><a name="version">version()</a></h3>
      <p class="item_brief">Returns the PCRE version used by this binding. </p>
      <p class="faldoc_funcdecl">Regex.version( )</p>
      
         <table class="faldoc_function">
         
         
         <tr><td class="faldoc_funcreturn">Returns:</td><td class="faldoc_funcreturndesc">A string containing a descriptive PCRE version message. </td></tr>
         
         </table>
      
      <p class="faldoc_text"><p class="faldoc_text">This function can be used to retreive the PCRE version that is currently used by the REGEX module. </p>
</p>
   

<hr/>
<div class="navibottom">
   <center>
      <a href="./index.html">Main</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="./modules.html">Modules</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="./pages.html">Related pages</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="./groups.html">Groups</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="./classes.html">Classes</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="./objects.html">Objects</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="./functions.html">All functions</a>&nbsp;&nbsp;-&nbsp;&nbsp;<a href="./enum.html">Enumerations</a>
   </center>
</div>
</div>
<div class="faldoc_signature">Made with <a href="http://www.falconpl.org">faldoc 2.2.0</div>
</body>
</html>