I would like to have some perl regex to replace any non-word characters like so:
s/\W//g;
However, if there are two colons following eachother like ::, I would not like to replace those. Does anyone know how to accomplish this? Thanks!
/\W/ is /[^\w]/, so /[^\w:]/ would delete every non-word char except colons.
You also want to delete lone colons (/(?<!:):(?!:)/), so the final solution is
s/[^\w:]|(?<!:):(?!:)//g;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With