Search code examples
stringfluttertextdouble-quotes

How to get quoted text from string in flutter?


I have a string which may contain quoted text, something like this String question = 'Vertices of the triangle are "(5,-2),(-1,2)(1,4)"' I want to get that quoted text from the string and store it in another string like this. String numbers = '(5,-2),(-1,2),(1,4)'

I have tried finding a solution and I have tried to read the documentation on string but couldn't find a solution.


Solution

  • You can do it with a regular expression:

    final String question = 'Vertices of the triangle are "(5,-2),(-1,2)(1,4)"';
    final match = RegExp(r'"((?:\\.|[^"\\])*)"').firstMatch(question);
    print(match?.group(1));