I want to validate the string to be an integer of such format of undefined length.
/\A (?<d> ( ( (\g<d>[[:space:]])? \d)? \d)? \d) \z/x === "12 123 123"
but it throws
SyntaxError: never ending recursion
I want to validate the string to be an integer of such format of undefined length.
/\A (?<d> ( ( (\g<d>[[:space:]])? \d)? \d)? \d) \z/x === "12 123 123"
but it throws
SyntaxError: never ending recursion
It seems you can use
Or, to support any kind of whitespace:
Details:
\A- start of a string\d{1,3}- one, two or three digits(?:[[:space:]]\d{3})*- zero or more occurrences of a whitespace and then three digits\z- end of string.See the Rubular demo.
Also, see Fastest way to check if a string matches a regexp in ruby? how to check if a string matches a regex in Ruby. In short, it is
your_pattern.match?(your_string).