user2924482 user2924482 - 5 months ago 9
Swift Question

Swift: Combine two or more regular expressions

I'm using two regular expressions:

var myNumbers = numbers.text?.stringByReplacingOccurrencesOfString("[^0-9]", withString: "", options: NSStringCompareOptions.RegularExpressionSearch, range:nil)


myNumbers = myNumbers?.stringByReplacingOccurrencesOfString("^\\s*$", withString: "", options: NSStringCompareOptions.RegularExpressionSearch, range:nil)


I'm removing non number characters and spaces but there a way to combine the regular expressions ?

Answer
 var myNumbers  = numbers.text?.stringByReplacingOccurrencesOfString("[\\s\\D]", withString: "", options: NSStringCompareOptions.RegularExpressionSearch, range:nil)