如何在Ruby中编写REGEX以确保字符串仅为整数。例如确保字符串只包含int或浮点数
3 --> Returns true
3g --> Returns False
4.3 --> Returns False
同样,如何编写REGEX以确保它是浮动的? 例如
3 --> Returns False
3g --> Returns False
4.3 --> Returns True
我需要int和float的REGEX。我认为int只是/ \ d + /和/\d+.\d+/,但不起作用。
很简单。谢谢。 :) – user3187131
“-3.1415927”或“-11”呢? –
另外,'3'也是一个有效的浮点数。 – BroiSatse