You're close. Try:
var re = RegExp(r'(?=<link=".*?">)|(?<=</link>)');
It has two differences from your RegExp:
- It swaps the
(?=
and (?<=
because you want a split before a <link...>
, so you want a lookahead for that, and after a </link>
, so a lookbehind for that.
- I added the
?
to ".*?"
, because otherwise it could potentially match until a later "
on the same line, instead of the first one. Your example didn't have that, but better safe than sorry.
With that, you get the strings:
"This is first text "
"<link="www.stackoverflow.com">First Hello</link>"
"
This is the second text "
"<link="www.stackoverflow.com">Second</link>"
"
"
If you don't want the newlines to be included, you should probably remove them first.
if you want to combine the
with the </link>
, you can change the RegExp to
var re = RegExp(r'(?=<link=".*?">)|(?<=</link>
*(?<=
))');
That gives you:
"This is first text "
"<link="www.stackoverflow.com">First Hello</link>
"
"This is the second text "
"<link="www.stackoverflow.com">Second</link>
"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…