C#/Winform
(C#) 특수문자 제거 정규식
kjun.kr
2017. 12. 27. 00:34
728x90
input 문자열에 특수 문자가 있다면 isSpecial 에 true 가 반환된다.
string input = @"특수문자가 있습니까?!@#$%^&~.!";
bool isSpecial = Regex.IsMatch(input, @"[^a-zA-Z0-9가-힣]");
[^a-zA-Z0-9가-힣] 은 앞에 ^ 표시가 붙어 부정을 의미한다.
그러므로 a-zA-Z0-9가-힣 사이에 있는문자가 아닌게 있는지 확인하는 것이다.
제거는
input = Regex.Replace(input, @"[^a-zA-Z0-9가-힣]", "", RegexOptions.Singleline);
728x90