matchAsPrefix method

  1. @override
Match? matchAsPrefix(
  1. String input, [
  2. int start = 0
])
override

Matches this pattern against the start of string.

Returns a match if the pattern matches a substring of string starting at start, and null if the pattern doesn't match at that point.

The start must be non-negative and no greater than string.length.

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

Implementation

@override
Match? matchAsPrefix(String input, [int start = 0]) {
  RangeError.checkValueInInterval(start, 0, input.length, 'start');
  final end = tryMatch(input, start, input.length);
  if (end >= start) {
    return RegexpMatch(this, input, start, end);
  }
  return null;
}