From f15e8cbffccae6b7bbf6ffc998c4c2520210d539 Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 1 May 2024 13:07:37 +0100 Subject: [PATCH] added doc to RegExp.firstMatch for getting first match from offset --- sdk/lib/core/regexp.dart | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/sdk/lib/core/regexp.dart b/sdk/lib/core/regexp.dart index f8f0efa65812..9ed38d33b93e 100644 --- a/sdk/lib/core/regexp.dart +++ b/sdk/lib/core/regexp.dart @@ -305,6 +305,13 @@ abstract interface class RegExp implements Pattern { /// final match = regExp.firstMatch(string)!; /// print(match[0]); // chat /// ``` + /// + /// If we need to find the [firstMatch] but starting from an offset, we can + /// achieve this using the [allMatches] method. Because [allMatches] is lazy, + /// it wont match beyond the first [RegExpMatch]. + /// ``` + /// RegExpMatch? match = pattern.allMatches(source, start).firstOrNull; + /// ``` RegExpMatch? firstMatch(String input); Iterable allMatches(String input, [int start = 0]);