C#正则表达式 官网
正则表达式是用于匹配字符串模式的工具。在C#里,可借助System.Text.RegularExpressions命名空间运用正则表达式。 // 示例1:检查字符串是否包含数字using System;using System.Text.RegularExpressions;class Program { static void Main() { string input = "abc123"; bool hasNumber = Regex.IsMatch(input, @"\d"); Console.WriteLine(hasNumber); // 运行结果:True }} 正则表达式的模式可依据具体需求灵活调整。 使用正则表达式时,要留意转义字符的运用,像\d代表匹配数字。