import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "(^|[+-]?\\d+\\.\\d*)$";
final String string = "TICKER|LAST_UPDE|PX_LAST\n"
+ "EE0002M Index|20211231|-0.58814\n"
+ "US0002M Index||\n"
+ "USB3MAY Index|20220502|0.8x9\n"
+ "SOFRRATE Index|20220505|c0.79\n"
+ "FEDL01 Index|20220505|0.83\n"
+ "US0001M Index|2022050|0.84486\n"
+ "FDTR Index|20220505|1\n"
+ "US0003M Index|20220505|1.37071\n"
+ "PRIME Index|20220505|4\n"
+ "TICKER|LAST_UPDATE|PX_LAST\n"
+ "EE0002M Index|20211231|-0.58814\n"
+ "US0002M Index|20211231|0.1525\n"
+ "USB3MAY Index|20220502|0.89\n"
+ "PRIME Index|20220503|3.5\n"
+ "SOFRRATE Index|20220504|0.3\n"
+ "FEDL01 Index|20220504|0.33\n"
+ "US0001M Index|20220504|0.84514\n"
+ "FDTR Index|20220504|0.5\n"
+ "US0003M Index|20220504|1.40614\n\n";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
if (matcher.find()) {
System.out.println("Full match: " + matcher.group(0));
for (int i = 1; i <= matcher.groupCount(); i++) {
System.out.println("Group " + i + ": " + matcher.group(i));
}
}
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html