I have a very long string and I want to find the CAS number from that string which has some pattern as below:
2 to 7 digits-2 digits-1 digit
example :
1154-12-6, 127946-96-2
I am using following Regex to get this number:
str.match(/([0-9]{2,7})-([0-9]{2})-[0-9]/)
but for an example consisting "29022-11-5", it is giving me ["29022-11-5", "29022", "11"].
Please let me know how can I do it.
console.log(
"A long string with a number 29022-11-5 somewhere".match(/([0-9]{2,7})-([0-9]{2})-[0-9]/)
)
// it is giving me ["29022-11-5", "29022", "11"].