Skip to content

RegExp properties not applying when adding more than one annotation #71

@ibrahimEltayfe

Description

@ibrahimEltayfe

Hi, I'm encountering an issue when using multiple annotations when specifying multiLine or unicode or any other properties in the RegExp . I'm using the following regex patterns to detect hashtags and mentions in text:

final RegExp hashtagTextRegex = RegExp(
    r'#([\p{L}\p{N}_]+)',
    multiLine: true,
    unicode: true
);

final RegExp mentionTextRegex = RegExp(
    r'@([\p{L}\p{N}_]+)',
    multiLine: true,
    unicode: true
);

the problem is when using these two annotations, multiLine and unicode is not applying, maybe the problem is in this method _mergeRegexPatterns

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

    // replacing groups '(' => to non capturing groups '(?:'
    return RegExp(
      annotations
          .map(
            (a) =>
                '(${a.regExp.pattern.replaceAll(_nonCapturingGroupPattern, '(?:')})',
          )
          .join('|'),
    );
  }

when merging annotations, it does not apply the other properties of the regex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions