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 trying to use the built in function .replacingOccurences(of:) and passing in my RegEx as the string-protocol, while the code compiles, no changes are made.
Online there are many resources on how to replace occurrences in Swift however, the solutions are far more complicated than what seems to be nessacary.
How can I properly return this output (Current Strategy):
let word = "Hello World!!"
func regEx(word: String) -> String {
return word.replacingOccurrences(of: "/[^\\w]/g", with: "")
}
// return --> "HelloWorld"
"\\W+"....