1.判断为字母或数字
private void bool isNumOrAlp(string str)
{
string pattern= @"^[A-Za-z0-9]+$"; //@意思忽略转义,+匹配前面一次或多次,$匹配结尾
Match match = Regex.Match(str,pattern);
return match.Success;
}
2.截取数字和非数字
// 去掉字符串中的数字
public static string RemoveNumber(string key)
{
return Regex.Replace(key, @"\d", "");
}
//去掉字符串中的非数字
public static string RemoveNotNumber(string key)
{
return Regex.Replace(key, @"[^\d]*", "");
}