Why does the following Regex return two matches?
Regex: [^,]*
Input: AB
Output (Two matches):
|AB|
||
I am expecting only one match, AB
I tried it in a couple of Regex testers, it's not a language specific issue.
Test it here: https://regex101.com/r/fjT79V/2
Sample code (Java):
public static void main(String[] args) {
Pattern p = Pattern.compile("[^,]*");
Matcher m = p.matcher("AB");
while (m.find())
System.out.println("|" + m.group() + "|");
}