vendredi 31 juillet 2015

Extracting strings from one long string

I have a string like this

"[0.01,3.45],[5.674,8.712],[4.321,8.892],[3.412,6.781]"

I need to extract each pair of numbers so that each pair is a separate string in a String array

i.e. I want: {"0.01,3.45","5.674,8.712","4.321.8.892","3.412,6.781"}

This is the code I have:

    Pattern pattern = Pattern.compile("\\[(.*?)\\]");
    String[] result = pattern.split(myString);

.. and I get {"",",",",",","}

I have tried some different regex expressions as well but they just gave me an array with ONE (long) string element which obviously something I don't want either

Is the problem the regex expression or should I be using different code?

Thanks.

Aucun commentaire:

Enregistrer un commentaire