mergeRegexPatterns static method

RegExp? mergeRegexPatterns(
  1. List<FitAnnotation>? annotations
)

Merges multiple regex patterns from annotations

Implementation

static RegExp? mergeRegexPatterns(List<FitAnnotation>? annotations) {
  if (annotations == null || annotations.isEmpty) {
    return null;
  } else if (annotations.length == 1) {
    return annotations[0].regExp;
  }

  final nonCapturingGroupPattern = RegExp(r'\((?!\?:)');

  return RegExp(
    annotations
        .map(
          (a) =>
              '(${a.regExp.pattern.replaceAll(nonCapturingGroupPattern, '(?:')})',
        )
        .join('|'),
  );
}