From Wiki,
- ? => Matches the preceding element zero or one time. For example, ab?c matches only "ac" or "abc".
- | => The choice (also known as alternation or set union) operator matches either the expression before or the expression after the operator. For example, abc|def matches "abc" or "def".
Here is the code tried;
String yuStr = "-7.00, 10.00, 0.00, -212.000";
//Using ?
System.out.println(yuStr.replaceAll("-?(\\d+)\\.\\d+", "$1"));
//Using |
System.out.println(yuStr.replaceAll("-|(\\d+)\\.\\d+", "$1"));
However, both of two ways will give the same output
7, 10, 0, 212
Is my assumption right, according to Wiki doc above, in second way with ?, it is choice between expression before operator -
and expression after operator (\\d+)
?
My question is, why the second way (with |) is working the same way like first one (with ?) ?