lundi 2 mars 2015

Split with Regex not returning properly with numbers

I'm trying to split a string in two using a regex. The input string is in the format "Something something something 30min" for example. It always ends with a time in minutes in this format. I need to split it into "Something something something" and "30min". My solution right now is:



String[] separatedLine = line.split("(?=(\\d)+)" );


But then I get "Something something something" and 3. If I try instead:



String[] separatedLine = line.split("(?=(\\d\\d))" );


It works, but I do not know the size of my number, it can be 5 or it can be 180 for all I know. I tried many different combinations but none seem to do the trick for every case.


Aucun commentaire:

Enregistrer un commentaire