'Get all text between two parentheses but not a specific word

Use Regex to highlight all text between two parentheses but not a specific word

ex: "This is a << long text used just as an example to test >> how I can use Regex"

There are words between << >> I need to have two different styles, one for any text between <<>> and another one for only the bold text: example

"long text.......to test" will be in RED

ONLY "simple" will be in GREEN

any other words which outside the parentheses will be in Black

I'm using flutter_parsed_text package

    ParsedText(
      text: widget.text,          \\The main text which to be parsed with regex
      style: TextStyle(color: Colors.black), \\defult style if none is matching
      parse: [

//1st pattern match anything between <<>>
        MatchText(
            pattern: "\<<(.*?)\>>", // " << everything but not $searchKeyword >> "
            style: TextStyle(color: ColorsUtils.red),
            ),

//2nd pattern match the searchKeyword which in not selected in any pattern
            MatchText(
              pattern: '$searchKeyword',
              style: TextStyle(color: Colors.green),
            )
      ],
    );


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source