正则表达式练习——将文本中的日期格式化为标准格式
来源:互联网 发布:淘宝上便宜的羊毛被 编辑:程序博客网 时间:2024/05/21 11:31
//匹配文本中的日期,并将日期转换为标准格式void dateFormatEx(void){ ifstream in(".\\chapter.23.4.1.in", ios::binary); if (!in)cerr << "no file\n"; boost::regex pat("([\\d]+) ([\\w]+) ([\\d]+)"); cout << "pattern: " << pat << '\n'; int lineno = 0; string line; while (getline(in, line)) { ++lineno; boost::smatch matches; if (boost::regex_search(line, matches, pat)) { string day = matches[1]; string mon = matches[2]; string year = matches[3]; line = boost::regex_replace(line, pat, year+"/"+mon+"/"+day); } cout << line << endl; }}
输入语料
xxx
xxx
From: John Doe jdoe@machine.example
To: Mary Smith mary@example.net
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
Message-ID: <1234@local.machine.example>
This is a message just to say hello.
So, “Hello”.
From: Joe Q. Public john.q.public@example.com
To: Mary Smith <@machine.tld:mary@example.net>, , jdoe@test .example
Date: Tue, 1 Jul 2003 10:52:37 +0200
Message-ID: <5678.21-Nov-1997@example.com>
Hi everyone.
To: “Mary Smith: Personal Account” smith@home.example
From: John Doe jdoe@machine.example
Subject: Re: Saying Hello
Date: Fri, 21 Nov 1997 11:00:00 -0600
Message-ID: abcd.1234@local.machine.tld
In-Reply-To: <3456@example.net>
References: <1234@local.machine.example> <3456@example.net>
This is a reply to your reply.
----
输出结果
- 正则表达式练习——将文本中的日期格式化为标准格式
- 正则表达式练习——将文本中的日期格式化为标准格式
- 将日期格式化为yyyy/MM/dd
- mysql将字符串格式化为日期
- 怎样将Excel中的日期格式转换为文本格式
- javascript 将日期格式化为yyyy-MM-dd格式
- Python 正则表达式将纯文本转化为HTML格式
- java正则表达式——判断日期格式
- 正则表达式判断日期格式
- 正则表达式判断日期格式
- 正则表达式---更改日期格式
- 日期时间格式正则表达式
- 正则表达式判断日期格式
- JAVA将十位时间戳格式化为日期Date类型
- js将long日期格式转换为标准日期格式
- js将long日期格式转换为标准日期格式
- js将long日期格式转换为标准日期格式
- js将long日期格式转换为标准日期格式
- 中文Ubuntu里用户目录里的路径改成英文
- 大家刚上线的新站如何做好seo站内优化,我谈谈自己的看法!
- 链表的基本操作应用2---remove
- iOS学习网站和博客地址收集
- CCScaleTo与CCScaleBy比较
- 正则表达式练习——将文本中的日期格式化为标准格式
- httpQuery 强大的网络下载函数
- 使用用户定义数组访问表单输入
- 黑马程序员--java高级视频_io输入与输出
- 如何用STUN协议搭建跨网络监控环境
- CentOS 6.6 安装Nginx
- 微信开发-实现jsapi ticket
- 【机房重构】构造方法
- Ubuntu下安装eclipse