Regex Help - numbers from string

I’m trying to use Regex to extract a few numbers in a string.

Here’s the string (no quotes, only in bold) “Total space is 63 GB. Space free: 31 GB (50%).

I need two different regex expressions the first one would only extract the number 63 after “Total space is " and before " GB” I only need the number. but this number can vary in length. It may be 1,2,3,4 digits long.

The second expression would need to pull the 31 after “Space free: " and before " GB” again this number can vary in length.

Any help would be greatly appreciated.:slightly_smiling_face:

anyone on here use RegEX?

The following page allows you to test out different scenarios:

Test it here:
https:// regex101 . com

Posible solution: -?[0-9]+(?:,[0-9]+)?
Source: https:// stack overflow. com/questions/15894729/extract-number-from-string-using-regex-in-java

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.