Regex to include decimals
(\d+)[^0-9]+(\d+)[^1-9]+(\d+)The above expression recognizes three consecutive groups of integers. How would it also recognize decimals?
for example:
234.34 x 455.44 x 455.33the result:
(1) 234.34 (2) 455.44 (3) 455.33 1 Answer
If there is allways 3 groups, use:
(\d+(?:\.\d+)?)\D+(\d+(?:\.\d+)?)\D+(\d+(?:\.\d+)?)This will match 3 groups of float/integer.
Expanation:
( # start group 1 \d+ # 1 or more digits (?: # start non capture group \. # dot \d+ # 1 or more digits )? # end group, optional
) # end group 1
\D+ # 1 or more non digitsSame explanation for the rest of regex.
If you want to match only float (not integer), use: (\d+\.\d+)\D+(\d+\.\d+)\D+(\d+\.\d+)