I have a regex that checks if a string is a number. The thousands separator format is a space; the decimal separator is a period. The after-decimal part is optional.
The problem is that at some point, the String.matches () function stops working as expected. What worked before doesn't work anymore.
For example, the JUnit code:
import junit.framework.Assert;
import org.junit.Test;
public class RegExTest {
@Test
public void testThousandSeperatorRegex()
{
String regEx = "([0-9]{1,3}( [0-9]{3})*(\\.[0-9]+)?|\\.[0-9]+)";
Assert.assertEquals(true, "1".matches(regEx));
Assert.assertEquals(true, "10".matches(regEx));
Assert.assertEquals(true, "100".matches(regEx));
Assert.assertEquals(true, "1 000".matches(regEx));
Assert.assertEquals(true, "10 000".matches(regEx));
Assert.assertEquals(true, "100 000".matches(regEx));
Assert.assertEquals(true, "1 000 000".matches(regEx));
Assert.assertEquals(true, "10 000 000".matches(regEx));
Assert.assertEquals(false, "10000.56".matches(regEx));
Assert.assertEquals(true, "8 734".matches(regEx));
}
}
"8 734" . "1 000", . , 4- , ( !).
, , , , . , . , - , , , , , .
. String.matches() ?
- ? ^$, String.matches . java.util.regex jregex, .
JDK 6u31.
.
UPD: , Q . , , , . , , . , .
, -, , , . , , .
, , , :). , Qs.