skip to Main Content

I am using this Regex in my Flutter App to find words enclosed by single-quotes that end with a .tr:

r"'[^'\]*(?:\.[^'\]*)*'s*.trb"

Now I need another expression that is almost the same but looks for words enclosed by dobule-quotes, ending with .tr and might contain escaped single-quotes.

I tried simply changing the single quotes to double quotes from the first expression, but Flutter is giving me errors… I need to escaped some characters but I can not make it work. Any idea?

An edge case it should match is:

"Hello, I'm Chris".tr

2

Answers


  1. You may use this regex for double quoted text that can have any escaped character followed by .tr and word boundary:

    r""""[^"\]*(?:\.[^"\]*)*"s*.trb"""
    

    RegEx Demo

    Login or Signup to reply.
  2. you need to use before every " in your RegExp’s source, try this:

    RegExp regExp = new RegExp(r'"[^"\]*(?:\.[^"\]*)*"s*.trb');
    
    print("${regExp.hasMatch('"Hello, I'm Chris".tr')}"); // result = true
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search