I found the following regex in one of the Android Source file:
String regex = "\\s+(?i)src=\"cid(?-i):\\Q" + attachment.mContentId + "\\E\"";
if(string.matches(regex)) {
Print -- Matched
} else {
Print -- Not Found
}
NOTE: attachment.mContentId will basically have values like C4EA83841E79F643970AF3F20725CB04@gmail.com
I made a sample code as below:
String content = "Hello src=\"cid:something@gmail.com\" is present";
String contentId = "something@gmail.com";
String regex = "\\s+(?i)src=\"cid(?-i):\\Q" + contentId + "\\E\"";
if(content.matches(regex))
System.out.println("Present");
else
System.out.println("Not Present");
This always gives "Not Present" as output.
But when I am doing the below:
System.out.println(content.replaceAll(regex, " Replaced Value"));
And the output is replaced with new value. If it is Not Present, then how could replaceAll work and replace the new value? Please clear my confusions.
Can anybody say what kind of content in string will make the control go to the if part?