Last Updated
Viewed 18 Times

I'm trying to validate an amount formatted with decimals and commas and it should allow only numbers.

True values:


I am trying to get 1 long (timestamp) and 3 floats out of the payload of a message, the string I am passing looks like this (ignore quotes):


with this method

private static void processAnglesMsg(String s) {
   final Pattern dataTFFFsplit = Pattern.compile( "[+-]([0-9]+),"
                                                + "[+-]([0-9]*[.])?[0-9]+,"
                                                + "[+-]([0-9]*[.])?[0-9]+,"
                                                + "[+-]([0-9]*[.])?[0-9]+,");
    Matcher data = dataTFFFsplit.matcher(s.trim());
    if(data.matches()) {
        Long time = Long.parseLong(;
        float yaw = Float.parseFloat(;
        float pitch = Float.parseFloat(;
        float roll = Float.parseFloat(;
        System.out.format("Angles - [%8d] Yaw: %08.3f Pitch: %08.3f Roll: %08.3f%n",time,yaw, pitch,roll);
    } else {
        if(debugLevel>=4) System.out.println("DEBUG processAnglesMsg: "+s);

I keep reaching the debug code with:

DEBUG processAnglesMsg: 5737540811294,359.306580,7.948747,6.6707006621*

so it looks like the pattern I have is not working and data.matches() is returning false, despite much searching I can't see what I have done wrong. I do want the pattern to allow for optional + or - even though my current data doesn't contain this.

I have this regular expression:


however it is failing when i have an amount such as this: 41022095.6

anything I am missing?

Looking for the above

1,2,3 is allowed 1, ____2_____,3_____, is allowed where _ is space 1 _ 2 _ 3 is not allowed where _ is space


Similar Question 7 (1 solutions) : Regular expression filter angular2

Similar Question 8 (5 solutions) : Regular expression with comma and numbers

Similar Question 9 (1 solutions) : Regular expression for comma separated string