Issue
I'm trying to make a regex to allow only a case of a number then "," and another number or same case seperated by ";" like
- 57,1000
- 57,1000;6393,1000
So far i made this: Pattern.compile("\\b[0-9;,]{1,5}?\\d+;([0-9]{1,5},?)+").matcher("57,1000").find();
which work if case is 57,1000;6393,1000
but it also allow letters and don't work when case 57,1000
Solution
try Regex "(\d+,\d+(;\d+,\d+)?)"
@Test
void regex() {
Pattern p = Pattern.compile("(\\d+,\\d+)(;\\d+,\\d+)?");
Assertions.assertTrue(p.matcher("57,1000").matches());
Assertions.assertTrue(p.matcher("57,1000;6393,1000").matches());
}
Answered By - Michael Katt
Answer Checked By - Gilberto Lyons (JavaFixing Admin)