String.replaceAll is considerably slower than doing the job yourself

While using regular expressions imparts some performance impact, it should not be as terrible. Note that using String.replaceAll() will compile the regular expression each time you call it. You can avoid that by explicitly using a Pattern object: Pattern p = Pattern.compile(“[,. ]+”); // repeat only the following part: String output = p.matcher(input).replaceAll(“”); Note also … Read more

Replacing \r\n with PHP

The main problem you have with all the variations you’ve tried is that both \n and \r are escape characters that are only escaped when you use them in a double-quoted string. In PHP, there is a big difference between ‘\r\n’ and “\r\n”. Note the single-quotes in the first, and double-quotes in the second. So: … Read more

Can I use sed to manipulate a variable in bash?

Try this: website=$(sed ‘s”https://stackoverflow.com/”\\/|g’ <<< $website) Bash actually supports this sort of replacement natively: ${parameter/pattern/string} — replace the first match of pattern with string. ${parameter//pattern/string} — replace all matches of pattern with string. Therefore you can do: website=${website////\\/} Explanation: website=${website // / / \\/} ^ ^ ^ ^ | | | | | | | … Read more