I am using a regular expression for finding string in between two strings
Code:
Pattern pattern = Pattern.compile("EMAIL_BODY_XML_START_NODE"+"(.*)(\\n+)(.*)"+"EMAIL_BODY_XML_END_NODE");
Matcher matcher = pattern.matcher(part);
if (matcher.find()) {
..........
It works fine for texts but when text contains special characters like newline it’s break
You need to compile the pattern such that
.matches line terminaters as well. To do this you need to use theDOTALLflag.edit: Sorry, it’s been a while since I’ve had this problem. You’ll also have to change the middle regex from
(.*)(\\n+)(.*)to(.*?). You need to lazy quantifier (*?) if you have multipleEMAIL_BODY_XML_START_NODEelements. Otherwise the regex will match the start of the first element with the end of the last element rather than having separate matches for each element. Though I’m guessing this is unlikely to be the case for you.