How should we replace <br /> html tags with line feed '\n' using RegExp in dart?
Input:
one<br />two<br />three
Output:
one
two
three
final _brRe = RegExp(r"<br\s*/>");
String replaceBreaks(String input) =>
input.replaceAll(_brRe, "\n");
You create a RegExp using the RegExp constructor, remembering to always use a raw string literal, so you don't need to double-escape backslashes.
Then you just use String.replaceAll to replace all substrings matched by the RegExp with a newline.
<br />s with newlines, and retains the One, two and three strings. Check: dartpad.dev/?id=a6b1cb1898e0aaa38ddb78a226790a34 . You must be doing something differently. Are you, by any chance, changing the regexp to r"<br.*/>"?
<br\s*/>would be a useful search regex.<br\s*/>should work.