How could I get only the first number from the strings below?
Regular expression should stop at space or first non-numeric character.
Examples:
6x2mL
7 x 5mL
100Subunits
2*5Kg
This will help you
String regEx = "^(\d+)";
OR
String regEx = "^([0-9]+)";
It will extract the first numeric value from given Strings.
Output :
6
7
100
2
Same problem is explained here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With