I am trying to match “\b\w+:” inside the string “Search\nPrefix with tag: app: or text:”
The code looks like:
String s = "Search\nPrefix with tag: app: or text:";
SpannableString str = SpannableString.valueOf(s);
Pattern regex = Pattern.compile("\\b\\w+:");
Matcher m = regex.matcher(str);
while(m.find()) {
// do stuff
}
I followed the code with the debugger, in Eclipse, and the while loop is never entered, meaning m.find() returns false.
I tried to change the regex to the straightforward
Pattern regex = Pattern.compile("app:");
It should work, right?, it is the same explicit text from the string. But still there is no match.
I suspect that the matcher stops matching when it reaches the newline in the string. And somehow there must be a flag or something to tell the matcher to scan the whole string.
My mistake, again.
I simplified the code to show it here, but in practice the while condition was
, and count was the culprit. The regex was OK.
The conclusion is: “Go to sleep if you are too tired to work”