I\'m trying to replace the occurrences of all spaces and special characters within a string in Swift.
I don\'t know what the RegEx would be in Swift.
I am tr
Additionally, you could extend String and accomplish the same bit. But if it's homework and they said function stick with that.
var word = "Hello World!!!"
extension String {
func regEx() -> String {
return self.replacingOccurrences(of: "\\W+", with: "", options: .regularExpression, range: nil)
}
}
word.regEx()