I have both used this Java specific regex tester and Regex101's tester
and both can find all 4 matches of a new-line starting with #
like in this sample string below. The string data comes from an UTF-8 file.
#1
#2
#3
#4
But only #2, #3, #4
is a positive match when running the Java code below in Android. Edit: I have found it that putting a empty line above #1
gets it matched which explains why all others get matched since they all have empty lines above them
Java code:
Pattern pattern = Pattern.compile("^#.*", Pattern.CASE_INSENSITIVE |
Pattern.MULTILINE);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
for (int i = 0; i <= matcher.groupCount(); i++) {
String foundWord = matcher.group(i);
}
}
It's like the matcher.find()
is completely skipping the first line