samedi 23 novembre 2019

JAVA Find parentheses surrounded sections in a String using Matcher/Pattern

I'm using this

Matcher m = Pattern.compile("-?\\d+(\\.\\d+)").matcher(strings);
 while(m.find()) {
     double value = Double.parseDouble(m.group());
     sb.append(value);

It works fine for the most part, but I'm trying to find numbers that may OR may NOT be surrounded by (parentheses). I'm wondering if its as simple as just changing this part
("-?\\d+(\\.\\d+)")

I tried using \p{Punct}? at the beginning and end; obviously, that didn't work.

Aucun commentaire:

Enregistrer un commentaire