If you're not used to regular expressions, @patrick dw's answer is probably better for you, but this should work too:
var strSource = "text-123-4567"; var rxNumbers = /\b(\d{3})-(\d{4})\b/ var arrMatches = rxNumbers.exec(strSource); var strFirstCluster, strSecondCluster; if (arrMatches) { strFirstCluster = arrMatches[1]; strSecondCluster = arrMatches[2]; }
This will extract the numbers if it is exactly three digits, followed by a dash, followed by four digits. An expression can be modified in many ways to get exactly the string you are using.
Andrew
source share