| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * [Match] contains methods to manipulate a regular expression match. | 6 * [Match] contains methods to manipulate a regular expression match. |
| 7 * | 7 * |
| 8 * Iterables of [Match] objects are returned from [RegExp] matching methods. | 8 * Iterables of [Match] objects are returned from [RegExp] matching methods. |
| 9 * | 9 * |
| 10 * The following example finds all matches of a [RegExp] in a [String] | 10 * The following example finds all matches of a [RegExp] in a [String] |
| 11 * and iterates through the returned iterable of [Match] objects. | 11 * and iterates through the returned iterable of [Match] objects. |
| 12 * | 12 * |
| 13 * [: | 13 * RegExp exp = const RegExp(@"(\w+)"); |
| 14 * RegExp exp = const RegExp(@"(\w+)"); | 14 * String str = "Parse my string"; |
| 15 * String str = "Parse my string"; | 15 * Iterable<Match> matches = exp.allMatches(str); |
| 16 * Iterable<Match> matches = exp.allMatches(str); | 16 * for (Match m in matches) { |
| 17 * for (Match m in matches) { | 17 * String match = m.group(0); |
| 18 * String match = m.group(0); | 18 * print(match); |
| 19 * print(match); | 19 * }; |
| 20 * }; | |
| 21 * :] | |
| 22 * | 20 * |
| 23 * The output of the example is: | 21 * The output of the example is: |
| 24 * | 22 * |
| 25 * [: | 23 * Parse |
| 26 * Parse | 24 * my |
| 27 * my | 25 * string |
| 28 * string | |
| 29 * :] | |
| 30 */ | 26 */ |
| 31 interface Match { | 27 interface Match { |
| 32 /** | 28 /** |
| 33 * Returns the index in the string where the match starts. | 29 * Returns the index in the string where the match starts. |
| 34 */ | 30 */ |
| 35 int start(); | 31 int start(); |
| 36 | 32 |
| 37 /** | 33 /** |
| 38 * Returns the index in the string after the last character of the | 34 * Returns the index in the string after the last character of the |
| 39 * match. | 35 * match. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 * [firstMatch] is the main implementation method that applies a regular | 72 * [firstMatch] is the main implementation method that applies a regular |
| 77 * expression to a string and returns the first [Match]. All | 73 * expression to a string and returns the first [Match]. All |
| 78 * other methods in [RegExp] can build on it. | 74 * other methods in [RegExp] can build on it. |
| 79 * | 75 * |
| 80 * Use [allMatches] to look for all matches of a regular expression in | 76 * Use [allMatches] to look for all matches of a regular expression in |
| 81 * a string. | 77 * a string. |
| 82 * | 78 * |
| 83 * The following example finds all matches of a regular expression in | 79 * The following example finds all matches of a regular expression in |
| 84 * a string. | 80 * a string. |
| 85 * | 81 * |
| 86 * [: | 82 * RegExp exp = const RegExp(@"(\w+)"); |
| 87 * RegExp exp = const RegExp(@"(\w+)"); | 83 * String str = "Parse my string"; |
| 88 * String str = "Parse my string"; | 84 * Iterable<Match> matches = exp.allMatches(str); |
| 89 * Iterable<Match> matches = exp.allMatches(str); | |
| 90 * :] | |
| 91 */ | 85 */ |
| 92 interface RegExp extends Pattern default JSSyntaxRegExp { | 86 interface RegExp extends Pattern default JSSyntaxRegExp { |
| 93 | 87 |
| 94 /** | 88 /** |
| 95 * Constructs a regular expression. The default implementation of a | 89 * Constructs a regular expression. The default implementation of a |
| 96 * [RegExp] sets [multiLine] and [ignoreCase] to false. | 90 * [RegExp] sets [multiLine] and [ignoreCase] to false. |
| 97 */ | 91 */ |
| 98 const RegExp(String pattern, [bool multiLine, bool ignoreCase]); | 92 const RegExp(String pattern, [bool multiLine, bool ignoreCase]); |
| 99 | 93 |
| 100 /** | 94 /** |
| 101 * Searches for the first match of the regular expression | 95 * Searches for the first match of the regular expression |
| 102 * in the string [str]. Returns [:null:] if there is no match. | 96 * in the string [str]. Returns `null` if there is no match. |
| 103 */ | 97 */ |
| 104 Match firstMatch(String str); | 98 Match firstMatch(String str); |
| 105 | 99 |
| 106 /** | 100 /** |
| 107 * Returns an iterable on the matches of the regular | 101 * Returns an iterable on the matches of the regular |
| 108 * expression in [str]. | 102 * expression in [str]. |
| 109 */ | 103 */ |
| 110 Iterable<Match> allMatches(String str); | 104 Iterable<Match> allMatches(String str); |
| 111 | 105 |
| 112 /** | 106 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 128 /** | 122 /** |
| 129 * Whether this regular expression matches multiple lines. | 123 * Whether this regular expression matches multiple lines. |
| 130 */ | 124 */ |
| 131 final bool multiLine; | 125 final bool multiLine; |
| 132 | 126 |
| 133 /** | 127 /** |
| 134 * Whether this regular expression is case insensitive. | 128 * Whether this regular expression is case insensitive. |
| 135 */ | 129 */ |
| 136 final bool ignoreCase; | 130 final bool ignoreCase; |
| 137 } | 131 } |
| OLD | NEW |