Detect numbers with two decimals?

Hi. I do need to detect all the number values that do have decimals with two places and generate a True boolean value for them, but I can’t find a proper way to do so. How can I use the Regex format to achieve this goal?

Numbers_Detect_Two_Decimals.gh (8.2 KB)


Numbers_Detect_Two_Decimals_2023Sep19a.gh (7.3 KB)

2 Likes

Thank you for the definition. Meantime I do found a RegEx solution: .\d\d

How can I use the Regex format to achieve this goal?

Assumming they’re strings of digits already, and you only want to match 2 or more d.p., in Python regex:

\d*\.\d\d+

\.\d{2}

I’m using this website to find the right pattern: RegExr: Learn, Build, & Test RegEx

3 Likes

This: .\d\d will give false positives for numbers with 2.d.p in.

I can’t remember the particulars of the flavour of Regex Grasshopper uses, but fairly universally a full stop (or dot, .) matches any character (except new lines and other special chars etc., depending on your special settings).

To only match a literal full stop you need to escape it: \.

1 Like