I’m trying use regular expression to convert special characters in an url. Here’s my sample code :
String formatUrl = "index.php?title=Test/enu/test/Tips_%26_Tricks/Tips_and_Tricks";
formatUrl = formatUrl.replaceAll("[^a-zA-Z0-9]" , "-");
What I’m trying to do is to convert the special characters in the url such as ?_%. to “-” excluding “/”.
The regular expression in my code converts everything resulting the output as
index-php-title-Test-enu-test-Tips--26-Tricks-Tips-and-Tricks
But I want it to be
index-php-title-Test/enu/test/Tips--26-Tricks/Tips-and-Tricks
Any pointers will be appreciated.
1 Answer