Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes between Version 10 and Version 11 of StdLib2/RegExp

Show
Ignore:
Author:
JarrettBillingsley (IP: 67.171.66.50)
Timestamp:
07/17/09 14:38:14 (15 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • StdLib2/RegExp

    v10 v11  
    1313These are some regexp strings which are defined for convenience. 
    1414 
    15  '''`regexp.email`''':: 
    16  Matches email addresses. 
     15=== '''`regexp.email`''' === 
    1716 
    18  '''`regexp.url`''':: 
    19  Matches HTTP URLs. 
     17Matches email addresses. 
    2018 
    21  '''`regexp.alpha`''':: 
    22  Matches lower- and upper-case letters and the underscore. 
     19=== '''`regexp.url`''' === 
    2320 
    24  '''`regexp.space`''':: 
    25  Matches all whitespace characters. 
     21Matches HTTP URLs. 
    2622 
    27  '''`regexp.digit`''':: 
    28  Matches all decimal digits. 
     23=== '''`regexp.alpha`''' === 
    2924 
    30  '''`regexp.hexdigit`''':: 
    31  Matches all hexadecimal digits. 
     25Matches lower- and upper-case letters and the underscore. 
    3226 
    33  '''`regexp.octdigit`''':: 
    34  Matches all octal digits. 
     27=== '''`regexp.space`''' === 
    3528 
    36  '''`regexp.symbol`''':: 
    37  Matches the following symbols: `( ) [ ] . , ; = < > + - * / & ^` 
     29Matches all whitespace characters. 
    3830 
    39  '''`regexp.chinese`''':: 
    40  Matches all valid Chinese characters. 
     31=== '''`regexp.digit`''' === 
    4132 
    42  '''`regexp.cnPhone`''':: 
    43  Matches valid Chinese phone numbers. 
     33Matches all decimal digits. 
    4434 
    45  '''`regexp.cnMobile`''':: 
    46  Matches valid Chinese mobile phone numbers. 
     35=== '''`regexp.hexdigit`''' === 
    4736 
    48  '''`regexp.cnZip`''':: 
    49  Matches valid Chinese ZIP codes. 
     37Matches all hexadecimal digits. 
    5038 
    51  '''`regexp.cnIDcard`''':: 
    52  Matches valid Chinese ID card numbers. 
     39=== '''`regexp.octdigit`''' === 
    5340 
    54  '''`regexp.usPhone`''':: 
    55  Matches valid USA phone numbers. 
     41Matches all octal digits. 
    5642 
    57  '''`regexp.usZip`''':: 
    58  Matches valid USA ZIP codes. 
     43=== '''`regexp.symbol`''' === 
     44 
     45Matches the following symbols: `( ) [ ] . , ; = < > + - * / & ^` 
     46 
     47=== '''`regexp.chinese`''' === 
     48 
     49Matches all valid Chinese characters. 
     50 
     51=== '''`regexp.cnPhone`''' === 
     52 
     53Matches valid Chinese phone numbers. 
     54 
     55=== '''`regexp.cnMobile`''' === 
     56 
     57Matches valid Chinese mobile phone numbers. 
     58 
     59=== '''`regexp.cnZip`''' === 
     60 
     61Matches valid Chinese ZIP codes. 
     62 
     63=== '''`regexp.cnIDcard`''' === 
     64 
     65Matches valid Chinese ID card numbers. 
     66 
     67=== '''`regexp.usPhone`''' === 
     68 
     69Matches valid USA phone numbers. 
     70 
     71=== '''`regexp.usZip`''' === 
     72 
     73Matches valid USA ZIP codes. 
    5974 
    6075== '''class Regexp''' == 
    6277This is a class whose instances represent compiled regular expressions.   
    6378 
    64  '''`this(pattern: string, attrs: string = "")`''':: 
    65  Compiles a regular expression string into an object.  The `pattern` parameter is the regular expression to compile.  The `attrs` parameter is a string containing extra attributes for the regexp.  Currently the only implemented attribute is "g", which means for the regexp to perform globally, that is, it will find all matches of a pattern in a string instead of just the first one. 
     79=== '''`this(pattern: string, attrs: string = "")`''' === 
    6680 
    67  '''`test(string: string)`''':: 
    68  Tests if `string` matches this pattern.  Returns `true` if it matches, and `false` otherwise.  If it returns `true`, the matches will be filled in, which can then be retrieved with the `match` method.  For example: 
     81Compiles a regular expression string into an object.  The `pattern` parameter is the regular expression to compile.  The `attrs` parameter is a string containing extra attributes for the regexp.  Currently the only implemented attribute is "g", which means for the regexp to perform globally, that is, it will find all matches of a pattern in a string instead of just the first one. 
     82 
     83=== '''`test(string: string)`''' === 
     84 
     85Tests if `string` matches this pattern.  Returns `true` if it matches, and `false` otherwise.  If it returns `true`, the matches will be filled in, which can then be retrieved with the `match` method.  For example: 
    6986 
    7087{{{ 
    7693}}} 
    7794 
    78  '''`match(m: int|string = 0)`''':: 
    79  This method has two forms.  If it is given 0, returns the current match (for use during iteration).  This is the default value, so you can call it without parameters.  If it is given a positive integer, returns the ''n''th parenthesized subexpression in the pattern.  If it is given a string, it looks for matches to this pattern in `string`, and returns an array of all the strings representing the matches. 
     95=== '''`match(m: int|string = 0)`''' === 
    8096 
    81  '''`find(string: string)`''':: 
    82  Looks for this pattern in `string`.  Returns the 0-based position if found, and the length of the string otherwise. 
     97This method has two forms.  If it is given 0, returns the current match (for use during iteration).  This is the default value, so you can call it without parameters.  If it is given a positive integer, returns the ''n''th parenthesized subexpression in the pattern.  If it is given a string, it looks for matches to this pattern in `string`, and returns an array of all the strings representing the matches. 
    8398 
    84  '''`split(string: string)`''':: 
    85  Splits `string` using this pattern as the delimiter.  Returns an array of the split-up string's components. 
     99=== '''`find(string: string)`''' === 
    86100 
    87  '''`replace(string: string, replacement: string|function)`''':: 
    88  If `replacement` is a string, replaces any matches in `string` with the replacement format string, returning the new string. If `replacement` is a function, it will call that function with an instance of the Regexp class for each match, and will expect that function to return a replacement string. This allows for very flexible replacements. This is a small example:  
     101Looks for this pattern in `string`.  Returns the 0-based position if found, and the length of the string otherwise. 
     102 
     103=== '''`split(string: string)`''' === 
     104 
     105Splits `string` using this pattern as the delimiter.  Returns an array of the split-up string's components. 
     106 
     107=== '''`replace(string: string, replacement: string|function)`''' === 
     108 
     109If `replacement` is a string, replaces any matches in `string` with the replacement format string, returning the new string. If `replacement` is a function, it will call that function with an instance of the Regexp class for each match, and will expect that function to return a replacement string. This allows for very flexible replacements. This is a small example:  
    89110 
    90111{{{ 
    103124Returns the completed string. 
    104125 
    105  '''`search(string: string)`''':: 
    106  This sets up the regex to start searching through the given `string`.  Immediately after calling this function, you should run a `foreach` loop on the object.  This is explained in `opApply`. 
     126=== '''`search(string: string)`''' === 
    107127 
    108  '''`opApply()`''':: 
    109  Once the regex has been set up to search a string with `search`, use this to iterate over the matches with a `foreach` loop.  This returns two indices for each iteration: the index of the current match (from 0), and the instance itself.  From the instance, you can obtain the value of the current match by calling `.match(0)` (or just `.match()`) on it, as well as using the `.pre()` and `.post()` methods.  Here's an example of use: 
     128This sets up the regex to start searching through the given `string`.  Immediately after calling this function, you should run a `foreach` loop on the object.  This is explained in `opApply`. 
     129 
     130=== '''`opApply()`''' === 
     131 
     132Once the regex has been set up to search a string with `search`, use this to iterate over the matches with a `foreach` loop.  This returns two indices for each iteration: the index of the current match (from 0), and the instance itself.  From the instance, you can obtain the value of the current match by calling `.match(0)` (or just `.match()`) on it, as well as using the `.pre()` and `.post()` methods.  Here's an example of use: 
    110133 
    111134{{{ 
    115138}}} 
    116139 
    117  '''`pre()`''':: 
    118  During iteration, returns the portion of the source string that comes before the current match. 
     140=== '''`pre()`''' === 
    119141 
    120  '''`post()`''':: 
    121  During iteration, returns the portion of the source string that comes after the current match. 
     142During iteration, returns the portion of the source string that comes before the current match. 
     143 
     144=== '''`post()`''' === 
     145 
     146During iteration, returns the portion of the source string that comes after the current match