It’s possible that I will either have
boundary=-------Embt-Boundary--1261032946D275CF
or
boundary="-------Embt-Boundary--1261032946D275CF"
and I want to just extract -------Embt-Boundary--1261032946D275CF
from the String.
How should I formed the regex? I have tried boundary="?(.+)("?)
but it only works for the first but for the second I’ll get the last double quote in my extracted string (eg. -------Embt-Boundary--1261032946D275CF"
).
2
Answers
You need:
Only one capture group used.
JS Demo:
The regular expression matches as follows:
boundary=
"?
(
[^"]+
"
(1 or more times (matching the most amount possible)))
"?
I believe flutter is Dart, which uses JavaScript regex specification, yes? Use capture groups in this way:
Group 1 will capture a quote if there is one. Group 2 will capture your desired result. Then,
1
will match the quote, if there was one, or nothing, if the quote was not present.regex101