Documentation update Pattern

Example codes added.

Closes https://github.com/dart-lang/sdk/pull/48005
https://github.com/dart-lang/sdk/pull/48005

GitOrigin-RevId: 7237529636f13def7069c5739376acff67462eb9
Change-Id: Ib41412f9a479b56868644370bf48c61ad3c71b8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/225580
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
This commit is contained in:
Alex Lindroos 2022-01-10 12:20:19 +00:00 committed by Commit Bot
parent e3181ae398
commit 9623410e47

View file

@ -20,6 +20,20 @@ abstract class Pattern {
/// and then from the end of the previous match (but always
/// at least one position later than the *start* of the previous
/// match, in case the pattern matches an empty substring).
/// ```dart
/// RegExp exp = RegExp(r'(\w+)');
/// var str = 'Dash is a bird';
/// Iterable<Match> matches = exp.allMatches(str, 8);
/// for (final Match m in matches) {
/// String match = m[0]!;
/// print(match);
/// }
/// ```
/// The output of the example is:
/// ```
/// a
/// bird
/// ```
Iterable<Match> allMatches(String string, [int start = 0]);
/// Matches this pattern against the start of `string`.
@ -29,6 +43,15 @@ abstract class Pattern {
/// at that point.
///
/// The [start] must be non-negative and no greater than `string.length`.
/// ```dart
/// final string = 'Dash is a bird';
///
/// var regExp = RegExp(r'bird');
/// var match = regExp.matchAsPrefix(string, 10); // Match found.
///
/// regExp = RegExp(r'bird');
/// match = regExp.matchAsPrefix(string); // null
/// ```
Match? matchAsPrefix(String string, [int start = 0]);
}