I have been trying to build a regular expression but haven’t been able to get one specific condition to work.
I want a regex to remove all non alpha characters with the exception of dash (-). Dashes should only be replaced if they are prefixed by a space.
I.e.
TEST-TEST -TEST#TEST.TEST
should be changed to
TEST-TEST TEST TEST TEST
I had been using [^a-zA-Z0-9] but haven’t been able to include one OR condition init.
Here is what I came up with
(\s-|[^A-Za-z0-9-])… It will remove all non alphanumerics but keep the “-” except if there is a space before it ” -“Test using sed in Linux, at the moment I don’t have access to VS or Mono to test in C#
Output
\s-[^A-Za-z0-9-]