hope this fix your issue urlencode() is intended for query parameters only (everything that goes after the ?). + is a special character inside the query part of the URL, and represents a literal space; literal + character needs to be percent-encoded. rawurlencode() is intended for all other URL parts, and it does not encode space as +. Dashes on the other hand are not special characters and represent themselves in the URL directly.
Remove special symbols and extra spaces and replace with underscore using the replace method
hop of those help? Your regular expression [^a-zA-Z0-9]\s/g says match any character that is not a number or letter followed by a space. Remove the \s and you should get what you are after if you want a _ for every special character.
var newString = str.replace(/[^A-Z0-9]/ig, "_");
var newString = str.replace(/[^A-Z0-9]+/ig, "_");
Properly sort an NSString array including words starting with a dash or special symbols (for a dictionary)