正则表达式中的组集合的使用
2006-11-17 15:25
281 查看
正则表达式中的组集合的使用
简单实例:
string s = "2005-2-21";
Regex reg = new Regex(@"(?<y>\d{4})-(?<m>\d{1,2})-(?<d>\d{1,2})",RegexOptions.Compiled);
Match match = reg.Match(s);
int year = int.Parse(match.Groups["y"].Value);
int month = int.Parse(match.Groups["m"].Value);
int day = int .Parse(match.Groups["d"].Value);
DateTime time = new DateTime(year,month,day);
简单实例:
string s = "2005-2-21";
Regex reg = new Regex(@"(?<y>\d{4})-(?<m>\d{1,2})-(?<d>\d{1,2})",RegexOptions.Compiled);
Match match = reg.Match(s);
int year = int.Parse(match.Groups["y"].Value);
int month = int.Parse(match.Groups["m"].Value);
int day = int .Parse(match.Groups["d"].Value);
DateTime time = new DateTime(year,month,day);
相关文章推荐
- Percona Toolkit命令使用集合(二)
- MDX语句使用随记002--如何在集合中排除某些成员
- 使用ActiveReport for .net 进行报表开发(三)--显示对象集合中的数据
- Java 集合系列之 LinkedList详细介绍(源码解析)和使用示例
- 关于使用Comparator对集合进行强制排序.
- Java中 Random随机用法与List集合配套使用实现随机点名
- 创建您自己的集合类(CollectinBase的使用)
- java 集合类使用笔记
- 迭代Iterator结合ArrayList集合的使用及基本使用,再看迭代Iterator原理
- Android tablayout集合fragment使用
- 使用Java实现面向对象编程--集合框架-->Vector和ArrayList
- 第十章 Scala 容器基础(十):使用for循环来遍历一个集合
- 熟练使用java集合002 List
- JAVA高级应用之集合 泛型 的使用
- java-集合(6)-TreeSet,HashSet与TreeSet比较,HashMap,TreeMap只有在排序的功能时使用
- git和github经常使用的命令集合
- 何时使用泛型集合
- 使用JackSon将对象和集合转为Json
- PHP 服务器使用正则表达式不能正常运行!
- VB6.0如何使用正则表达式