需要RegEx从字符串中删除所有字母 [英] Need RegEx to remove all alphabets from string
本文介绍了需要RegEx从字符串中删除所有字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一个正则表达式来移动字符串(A-Z)和(a-z)中的所有字母..包括任何特殊字符在内的所有内容都应保持不变.我尝试了@"[^ \ d]",但它只返回字符串中的数字.
I need a regex to move all alphabets from string (A-Z) and (a-z)..everything including any kind of special character should remain intact. I tried @"[^\d]" but it only returns numbers in string.
String : asd!@# $%dfdf4545D jasjkd #(*)jdjd56
desired output : !@# $%4545 #(*)56
推荐答案
只需用空字符串序列替换所有不需要的字符:
Just replace all undesired characters with an empty string sequence:
string filtered = Regex.Replace(input, "[A-Za-z]", "");
这篇关于需要RegEx从字符串中删除所有字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文