C#中的正则表达式的一些细节
2014-05-05 11:01
176 查看
在C#中用正则表达式需要引用using System.Text.RegularExpressions,在写正则表达式时要先写一个@
例如 string email = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";不然提示转义出现错误
string emailinput = Console.ReadLine();
判断是否匹配时,bool match = Regex.IsMatch(emailInput , email)
//Regex.IsMatch(string input , string pattern);注意参数的顺序。
代码:
例如 string email = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";不然提示转义出现错误
string emailinput = Console.ReadLine();
判断是否匹配时,bool match = Regex.IsMatch(emailInput , email)
//Regex.IsMatch(string input , string pattern);注意参数的顺序。
代码:
namespace test2 { class Program { static void Main(string[] args) { string email = @"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*";// while (true) { Console.Write("input:"); string emailInput = Console.ReadLine(); bool match = Regex.IsMatch(emailInput, email); if (match) { Console.WriteLine("legal"); } else { Console.WriteLine("illegal"); } } } } }
相关文章推荐
- C#代码实现邮箱验证C#中及一些常用的正则表达式
- 对C#中正则表达式的一些解读和总结
- C#代码实现邮箱验证C#中及一些常用的正则表达式
- 用正则表达式过滤脚本的一些研究(asp.net+C#)
- 一些有用的正则表达式,C#语言描述
- 对C#中正则表达式的一些解读和总结
- 自己总结的一些正则表达式(c#版)
- C#代码实现邮箱验证C#中及一些常用的正则表达式
- [转]c#一些常用的正则表达式总结
- 一些有用的C#正则表达式
- C#中判断是否为数字(及一些好用的正则表达式) [转]
- C#代码实现邮箱验证C#中及一些常用的正则表达式
- [转]C#代码实现邮箱验证C#中及一些常用的正则表达式
- C# 一些常用的正则表达式
- 总结的一些正则表达式(c#版)
- 用正则表达式过滤脚本的一些研究(asp.net + C#)
- C# 处理html 标签一些正则表达式 整理收集
- c#一些常用的正则表达式总结
- C#(正则表达式)Regex类的一些常见使用方式
- 用正则表达式过滤脚本的一些研究(asp.net + C#)