| 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 * RegExp exp = const RegExp(@"(\w+)"); | 13 * RegExp exp = const RegExp(@"(\w+)"); |
| 14 * String str = "Parse my string"; | 14 * String str = "Parse my string"; |
| 15 * Iterable<Match> matches = exp.allMatches(str); | 15 * Iterable<Match> matches = exp.allMatches(str); |
| 16 * for (Match m in matches) { | 16 * for (Match m in matches) { |
| 17 * String match = m.group(0); | 17 * String match = m.group(0); |
| 18 * print(match); | 18 * print(match); |
| 19 * }; | 19 * }; |
| 20 * | 20 * |
| 21 * The output of the example is: | 21 * The output of the example is: |
| 22 * | 22 * |
| 23 * Parse | 23 * Parse |
| 24 * my | 24 * my |
| 25 * string | 25 * string |
| 26 */ | 26 */ |
| 27 interface Match { | 27 abstract class Match { |
| 28 /** | 28 /** |
| 29 * Returns the index in the string where the match starts. | 29 * Returns the index in the string where the match starts. |
| 30 */ | 30 */ |
| 31 int start(); | 31 int start(); |
| 32 | 32 |
| 33 /** | 33 /** |
| 34 * 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 |
| 35 * match. | 35 * match. |
| 36 */ | 36 */ |
| 37 int end(); | 37 int end(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 50 List<String> groups(List<int> groups); | 50 List<String> groups(List<int> groups); |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * Returns the number of groups in the regular expression. | 53 * Returns the number of groups in the regular expression. |
| 54 */ | 54 */ |
| 55 int groupCount(); | 55 int groupCount(); |
| 56 | 56 |
| 57 /** | 57 /** |
| 58 * The string on which this matcher was computed. | 58 * The string on which this matcher was computed. |
| 59 */ | 59 */ |
| 60 final String str; | 60 String get str; |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * The pattern to search for in [str]. | 63 * The pattern to search for in [str]. |
| 64 */ | 64 */ |
| 65 final Pattern pattern; | 65 Pattern get pattern; |
| 66 } | 66 } |
| 67 | 67 |
| 68 | 68 |
| 69 /** | 69 /** |
| 70 * [RegExp] represents regular expressions. | 70 * [RegExp] represents regular expressions. |
| 71 * | 71 * |
| 72 * [firstMatch] is the main implementation method that applies a regular | 72 * [firstMatch] is the main implementation method that applies a regular |
| 73 * expression to a string and returns the first [Match]. All | 73 * expression to a string and returns the first [Match]. All |
| 74 * other methods in [RegExp] can build on it. | 74 * other methods in [RegExp] can build on it. |
| 75 * | 75 * |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 | 110 |
| 111 /** | 111 /** |
| 112 * Searches for the first match of the regular expression | 112 * Searches for the first match of the regular expression |
| 113 * in the string [str] and returns the matched string. | 113 * in the string [str] and returns the matched string. |
| 114 */ | 114 */ |
| 115 String stringMatch(String str); | 115 String stringMatch(String str); |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * The pattern of this regular expression. | 118 * The pattern of this regular expression. |
| 119 */ | 119 */ |
| 120 final String pattern; | 120 String get pattern; |
| 121 | 121 |
| 122 /** | 122 /** |
| 123 * Whether this regular expression matches multiple lines. | 123 * Whether this regular expression matches multiple lines. |
| 124 */ | 124 */ |
| 125 final bool multiLine; | 125 bool get multiLine; |
| 126 | 126 |
| 127 /** | 127 /** |
| 128 * Whether this regular expression is case insensitive. | 128 * Whether this regular expression is case insensitive. |
| 129 */ | 129 */ |
| 130 final bool ignoreCase; | 130 bool get ignoreCase; |
| 131 } | 131 } |
| OLD | NEW |