Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ibrahimEltayfe opened this issue Sep 2, 2024 · 0 comments

Comments

@ibrahimEltayfe
Copy link

ibrahimEltayfe commented Sep 2, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant