I am trying to check if a string can be converted to a number in FreeMarker. For example, “123” and “3.14” can be converted, but “foo” cannot. I know that I can check this using the number method in a string (for example "123"?number) and see if it causes an error, but I am looking for a way to check this without causing an error.
I tried ?matches("^\d+$")and it works great for integers, but I'm looking for something that works on all numbers.
Maybe I can do this using a more complex regex, but I'm wondering if there is an easier way.
source
share