I am trying to write a regex in Ruby to search a string for numbers of only four digits. I am using
/\d{4}/ but this is giving me number with four and more digits.
Eg: “12345-456-6575 some text 9897“
In this case I want only 9897 and 6575 but I am also getting 1234 which has a length of five characters.
1 Answer