Use non-ascii stripes, but allow currency symbols

I am using below regex to remove all non-ascii characters from string.

String pattern = @"[^\u0000-\u007F]";
Regex rx = new Regex(pattern, RegexOptions.Compiled);
rx.Replace(data," ");

      

However, I want to allow the use of curreny (pound symbol) and trademark symbols.

I changed the above regex as below and it works for me. Can anyone confirm if the regex is valid?

 String pattern = @"[^\u0000-\u007F \p{Sc}]";

      

Basically, I want to allow all currency symbols as well.

+3


source to share


1 answer


Yes, your regex is correct.

What you are doing with your code is replacing the characters that match your regex with a blank character.

Now what characters match your regex?

Everything except:



If you just want to keep some other symbols, yes, you can add them too (just like you did with \p{Sc}

.

Edit:

Be careful when doing this in the future. The regex would indeed be [^\u0000-\u007F\p{Sc}]

(no space), although it doesn't matter in this case since the space was already in the ASCII range.

+2


source







All Articles