RecursiveRegex constructor

RecursiveRegex({
  1. required Pattern startDelimiter,
  2. required Pattern endDelimiter,
  3. Pattern? inverseMatch,
  4. Pattern? prepended,
  5. Pattern? appended,
  6. String? captureGroupName,
  7. bool multiLine = false,
  8. bool caseSensitive = true,
  9. bool unicode = false,
  10. bool dotAll = false,
  11. bool global = false,
})

An implementation of RegExp that isolates delimited blocks of text and applies the delimiter pattern to each block separately.

startDelimiter and endDelimiter are required, must not be null, and must not be identical to each other.

If an inverseMatch pattern is provided, only matches that match that pattern and aren't delimited will be matched by this regex.

If prepended and/or appended are not null, all matched sets of delimiters will be validated to be preceded and/or followed by the values of prepended and/or appended respectively. All matched sets of delimiters that do not match the prepended and/or appended patterns will be excluded from the returned RegExpMatches.

Note: startDelimiter, endDelimiter, prepended, or appended are set as RegExps, their multiLine, caseSensitive, unicode, and dotAll parameters will be ignored. All patterns contained within those RegExps are rebuilt with this constructor's equivalent parameters.

If captureGroupName is not null the block of text captured between the delimiters will be captured in a group named it. captureGroupName must be a least 1 character long if not null.

multiLine, unicode, and dotAll are all false by default and must not be null.

caseSensitive is true by default and must not be null.

If global is true, every delimited block of text, nested or not, will be matched. If false, only the top-level blocks of delimited text will be matched.

Note: Due to the way this package isolates delimited text, the startDelimiter shouldn't start with and the endDelimiter shouldn't end with a token that captures whitespace. It will cause your matches to start at the beginning of and end at the length of the inputted string.

Implementation

RecursiveRegex({
  required this.startDelimiter,
  required this.endDelimiter,
  this.inverseMatch,
  this.prepended,
  this.appended,
  this.captureGroupName,
  bool multiLine = false,
  bool caseSensitive = true,
  bool unicode = false,
  bool dotAll = false,
  this.global = false,
})  : assert((startDelimiter is String && startDelimiter != endDelimiter) ||
          (startDelimiter is RegExp &&
              endDelimiter is RegExp &&
              startDelimiter.pattern != endDelimiter.pattern)),
      assert(captureGroupName == null || captureGroupName.length > 1),
      isMultiLine = multiLine,
      isCaseSensitive = caseSensitive,
      isUnicode = unicode,
      isDotAll = dotAll;