I have regex=""
and a String str="stackoveflow";
I don't understand why it is matching every character in the string. can you explain to me?
public class test {
public static void main(String[] args){
Console console = System.console();
String str="stackoveflow";
Pattern pattern = Pattern.compile("");
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
console.format("I found the text" +
" \"%s\" starting at " +
"index %d and ending at index %d.%n",
matcher.group(),
matcher.start(),
matcher.end());
}
}
}
Output is:
I found the text "" starting at index 0 and ending at index 0. I found the text "" starting at index 1 and ending at index 1. I found the text "" starting at index 2 and ending at index 2. I found the text "" starting at index 3 and ending at index 3. I found the text "" starting at index 4 and ending at index 4. I found the text "" starting at index 5 and ending at index 5. I found the text "" starting at index 6 and ending at index 6. I found the text "" starting at index 7 and ending at index 7. I found the text "" starting at index 8 and ending at index 8. I found the text "" starting at index 9 and ending at index 9. I found the text "" starting at index 10 and ending at index 10. I found the text "" starting at index 11 and ending at index 11. I found the text "" starting at index 12 and ending at index 12.