随笔 - 493  文章 - 0  评论 - 97  阅读 - 239万

在VC6中使用正则表达式解析字符串

From: http://school.cnd8.com/vc/jiaocheng/33274.htm

参考上面网址中的文章,写了下面的例子,环境:windows XP SP3 +  VC6

#include <cstdlib >
#include <stdlib.h >
#include <boost/regex.hpp>
#include <string>
#include <iostream>
using namespace std;
using namespace boost;
 
int main(int argc, char * argv[])
{
    regex expression("(\\d+)-(\\d+)-(\\d+)"); // 注意转义方式
    string in("Today: 2007-06-23");
    cmatch what;
    // 如果用 regex_match 方法将需要完全匹配,
    // 不能在字符串中找寻模式,可用于验证输入
    if (regex_search(in.c_str(), what, expression))
    {
        for(int i = 0 ; i < what.size(); i++)
        {
            cout<<"str: "<<what[i].str()<<endl;
        }
    }
    return 0;
程序运行结果:
str: 2007-06-23
str: 2007
str: 06
str: 23
Press any key to continue

 

注意:

本文所使用的boost库版本为:boost_1_34_0。请大家一定要看清楚了,一些高版本的boost库已经不再支持vc6了,而是支持更高版本的Visual Studio IDE(7.1以上)。

另外,编译之前,需要将libboost_regex-vc6-sgd-1_34.lib拷贝到程序根目录下,该文件是在“nmake -f vc6.mak”时产生的。

posted on   清清飞扬  阅读(2493)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET10 - 预览版1新功能体验(一)
< 2010年11月 >
31 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 1 2 3 4
5 6 7 8 9 10 11

点击右上角即可分享
微信分享提示