I am trying to make a Regex pattern that will get anything within the <body></body>
tags in some html. I have made a small example of what I have tried:
void main() {
Iterable<Match> matches = extractHTML.allMatches(example);
for (Match m in matches) {
String match = m.group(0);
print(match);
}
}
final RegExp extractHTML =
RegExp(r"<body\b[^>]*>(.*?)</body>"); //r"<html\b[^>]*>(.*?)</html>");
final String example = """
<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n<meta name=\"Generator\" content=\"Microsoft Word 15 (filtered medium)\">\r\n<style></style>\r\n</head>\r\n<body lang=\"EN-GB\" link=\"#0563C1\" vlink=\"#954F72\">\r\n <div class=\"WordSection1\">\r\n <p class=\"MsoNormal\"><span style=\"font-size:12.0pt\">Good morning,</span></p>\r\n<p class=\"MsoNormal\"><span style=\"font-size:12.0pt\"> </span></p>\r\n<p class=\"MsoNormal\"> <span style=\"font-size:12.0pt\">The telephone in Reception is not working properly this morning and I have no CCTV coverage either. Could someone possibly come and have a look? I have turned the system off and on again but still the same.\r\n Help!</span></p>\r\n<p class=\"MsoNormal\"><span style=\"font-size:12.0pt\"> </span></p>\r\n</div>\r\n</body>\r\n</html>
""";
I am expecting that this code will print the data within the tags but the console doesn't print anything. I have tried using this same RegExp
on here using the same RegExp
and string and it does as I expect it to. Is this something to do with me not escaping characters correctly? I thought the r
before a string implied the string was literal.