| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * [Match] contains methods to manipulate a regular expression match. | |
| 7 * | |
| 8 * Iterables of [Match] objects are returned from [RegExp] matching methods. | |
| 9 * | |
| 10 * The following example finds all matches of a [RegExp] in a [String] | |
| 11 * and iterates through the returned iterable of [Match] objects. | |
| 12 * | |
| 13 * RegExp exp = const RegExp(@"(\w+)"); | |
| 14 * String str = "Parse my string"; | |
| 15 * Iterable<Match> matches = exp.allMatches(str); | |
| 16 * for (Match m in matches) { | |
| 17 * String match = m.group(0); | |
| 18 * print(match); | |
| 19 * }; | |
| 20 * | |
| 21 * The output of the example is: | |
| 22 * | |
| 23 * Parse | |
| 24 * my | |
| 25 * string | |
| 26 */ | |
| 27 interface Match { | |
| 28 /** | |
| 29 * Returns the index in the string where the match starts. | |
| 30 */ | |
| 31 int start(); | |
| 32 | |
| 33 /** | |
| 34 * Returns the index in the string after the last character of the | |
| 35 * match. | |
| 36 */ | |
| 37 int end(); | |
| 38 | |
| 39 /** | |
| 40 * Returns the string matched by the given [group]. If [group] is 0, | |
| 41 * returns the match of the regular expression. | |
| 42 */ | |
| 43 String group(int group); | |
| 44 String operator [](int group); | |
| 45 | |
| 46 /** | |
| 47 * Returns the strings matched by [groups]. The order in the | |
| 48 * returned string follows the order in [groups]. | |
| 49 */ | |
| 50 List<String> groups(List<int> groups); | |
| 51 | |
| 52 /** | |
| 53 * Returns the number of groups in the regular expression. | |
| 54 */ | |
| 55 int groupCount(); | |
| 56 | |
| 57 /** | |
| 58 * The string on which this matcher was computed. | |
| 59 */ | |
| 60 final String str; | |
| 61 | |
| 62 /** | |
| 63 * The pattern to search for in [str]. | |
| 64 */ | |
| 65 final Pattern pattern; | |
| 66 } | |
| 67 | |
| 68 | |
| 69 /** | |
| 70 * [RegExp] represents regular expressions. | |
| 71 * | |
| 72 * [firstMatch] is the main implementation method that applies a regular | |
| 73 * expression to a string and returns the first [Match]. All | |
| 74 * other methods in [RegExp] can build on it. | |
| 75 * | |
| 76 * Use [allMatches] to look for all matches of a regular expression in | |
| 77 * a string. | |
| 78 * | |
| 79 * The following example finds all matches of a regular expression in | |
| 80 * a string. | |
| 81 * | |
| 82 * RegExp exp = const RegExp(@"(\w+)"); | |
| 83 * String str = "Parse my string"; | |
| 84 * Iterable<Match> matches = exp.allMatches(str); | |
| 85 */ | |
| 86 interface RegExp extends Pattern default JSSyntaxRegExp { | |
| 87 | |
| 88 /** | |
| 89 * Constructs a regular expression. The default implementation of a | |
| 90 * [RegExp] sets [multiLine] and [ignoreCase] to false. | |
| 91 */ | |
| 92 const RegExp(String pattern, [bool multiLine, bool ignoreCase]); | |
| 93 | |
| 94 /** | |
| 95 * Searches for the first match of the regular expression | |
| 96 * in the string [str]. Returns `null` if there is no match. | |
| 97 */ | |
| 98 Match firstMatch(String str); | |
| 99 | |
| 100 /** | |
| 101 * Returns an iterable on the matches of the regular | |
| 102 * expression in [str]. | |
| 103 */ | |
| 104 Iterable<Match> allMatches(String str); | |
| 105 | |
| 106 /** | |
| 107 * Returns whether the regular expression has a match in the string [str]. | |
| 108 */ | |
| 109 bool hasMatch(String str); | |
| 110 | |
| 111 /** | |
| 112 * Searches for the first match of the regular expression | |
| 113 * in the string [str] and returns the matched string. | |
| 114 */ | |
| 115 String stringMatch(String str); | |
| 116 | |
| 117 /** | |
| 118 * The pattern of this regular expression. | |
| 119 */ | |
| 120 final String pattern; | |
| 121 | |
| 122 /** | |
| 123 * Whether this regular expression matches multiple lines. | |
| 124 */ | |
| 125 final bool multiLine; | |
| 126 | |
| 127 /** | |
| 128 * Whether this regular expression is case insensitive. | |
| 129 */ | |
| 130 final bool ignoreCase; | |
| 131 } | |
| OLD | NEW |