Hi I need a regex to replace # or * with ""(emptyString) I have tried with /[\\*\\#]/g but does not seem to be working.
http://ideone.com/MtjsX5
please need your help in this.
I am actually using this a Grxml grammar as below
SWI_meaning = DIGITS.SWI_literal.replace( /[ ]+/g, '' );
SWI_meaning = SWI_meaning.replace( /[\*\#]/g, '' );
Thanks
Rather than regex, you can use char.IsDigit to filter out only digits from the string. Try the following.
string str = "123456#";
string newString = string.Join("",
str.Select(r=> char.IsDigit(r) ? r.ToString():""));
EDIT: courtesy @L.B
string newString = String.Join("",str.Where(char.IsDigit));
string str = "123456#";
string clean = Regex.Replace(str, @"[#*]", string.Empty);
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