boost 正则表达式 regex

 

环境安装

如果在引用boost regex出现连接错误,但是引用其他的库却没有这个错误,这是因为对于boost来说,是免编译的,但是,正则这个库 是需要单独编译和使用的。简单的办法就是 直接将boost库全部编译,然后 找到正则的lib,编译时候引用进去。

代码example

#include <boost/regex.hpp>
#include <iostream>
#include <string>
#include "TestRe.h" using namespace::boost;
using namespace::std; void TestRe::test() { regex re("(https?://www.ttufo.com/.+/.+/.+)(_\\d+)(.html?)"); //string replace("http://www.ttufo.com/($1)/($2)/($3).htm($5)");
//regex re("http://www.ttufo.com/(.+)/(.+)/(.+)(_.+).htm(l?)"); string target("http://www.ttufo.com/ufo/201705/154053_3.html"); cmatch what; if (regex_match(target.c_str(), what, re)) { cout << "match " << what.size() << endl; for (int i = 0; i < what.size(); i++) { cout << "what[" << i << "]: " << what[i] << ", first: " << what[i].first << ", second: " << what[i].second << endl;
}
} else {
cout << "not match " << endl;
} } void TestRe::test_replace() { cout << "test replac ----------------" << endl;
string s1 = "(<)|(>)|(&)";
// string s2 = "(?1b)(?2e)(?3...)";
string s2 = "(?1$1)(?2$2)(?3...)"; string target("cout << a&b << endl;");
boost::regex reg( s1 );
string s = boost::regex_replace( target,
reg,
s2,
boost::match_default | boost::format_all);
cout << s << endl; cmatch what; target = "cout << a&b << endl;";
if (regex_search(target.c_str(), what, reg)) { cout << "match " << what.size() << endl; for (int i = 0; i < what.size(); i++) { cout << "what[" << i << "]: " << what[i] << ", first: " << what[i].first << ", second: " << what[i].second << endl;
}
} else {
cout << "not match " << endl;
} cout << "test replac ----------------" << endl;
} void TestRe::test_replace_1() {
regex reg("(https?://www.ttufo.com/.+/.+/.+)(_\\d+)(.html?)"); string target("https://www.ttufo.com/ufo/201705/154053_3.html"); string replace("http://www.ttufo.com/($1)/($2)/($3).htm($5)");
replace = "($1)($3)";
string s = boost::regex_replace( target,
reg,
replace,
boost::match_default | boost::format_all); cout << "test replace 1" << endl;
cout << s << endl;
cout << "test replace1 end" << endl;
}
 

boost 正则表达式 regex的更多相关文章

  1. 转:C++ Boost/tr1 Regex(正则表达式)快速指南

    C++ Boost/tr1 Regex(正则表达式)快速指南 正则表达式自Boost 1.18推出,目前已经成为C++11(tr1)的标准部分. 本文以Boost 1.39正则表达式为基础,应该广泛适 ...

  2. (四)boost库之正则表达式regex

    (四)boost库之正则表达式regex 正则表达式可以为我们带来极大的方便,有了它,再也不用为此烦恼 头文件: #include <boost/regex.hpp> 1.完全匹配 std ...

  3. Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答

    Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答 Boost正则表达式库regex常用search和match示例 发表回复   Boo ...

  4. C#正则表达式Regex常用匹配

    使用Regex类需要引用命名空间:using System.Text.RegularExpressions; 利用Regex类实现验证 示例1:注释的代码所起的作用是相同的,不过一个是静态方法,一个是 ...

  5. C#正则表达式Regex类的用法

    C#正则表达式Regex类的用法 更多2014/2/18 来源:C#学习浏览量:36891 学习标签: 正则表达式 Regex 本文导读:正则表达式的本质是使用一系列特殊字符模式,来表示某一类字符串, ...

  6. C#正则表达式Regex类

    C#正则表达式Regex类的使用 C#中为正则表达式的使用提供了非常强大的功能,这就是Regex类.这个包包含于System.Text.RegularExpressions命名空间下面,而这个命名空间 ...

  7. VS2010中使用boost正则表达式库

    1.下载boost库.http://www.boost.org/ 我下载的是boost_1_51_0版本.放在D:\opensource\boost_1_51_0. 2.编译boost库.     执 ...

  8. 请写出正则表达式(regex),取得下列黄色部分的字符串 TEL: 02-236-9655/9659 FAX:02-236-9654 (黄色部分即02-236-9655/9659 ) ( 测试面试题)

    请写出正则表达式(regex),取得下列黄色部分的字符串 TEL: 02-236-9655/9659 FAX:02-236-9654 答: package test1; import java.uti ...

  9. Python 正则表达式(RegEx)

    版权所有,未经许可,禁止转载 章节 Python 介绍 Python 开发环境搭建 Python 语法 Python 变量 Python 数值类型 Python 类型转换 Python 字符串(Str ...

随机推荐

  1. vue 轮播图插件 vue-awesome-swiper

    1.npm安装 npm install vue-awesome-swiper --save 2.vue 引入 //在main.js 中全局引入 import VueAwesomeSwiper from ...

  2. jQuery-lazyload参数

    1.placeholder placeholder:'图片地址',用图片提前占据将要加载的图片的位置. 2.effect effect:‘fadeIn’ 表示用何种效果载入,eg:show()直接加载 ...

  3. Confluence 6 配置验证码(Captcha)来防止垃圾

    如果你的 Confluence 站点是对公众开放的(允许匿名用户使用,添加评论,创建页面等),你可能会发现你的站点会被自动创建很多垃圾页面,评论或者其他垃圾内容. 你可以配置让 Confluence ...

  4. Confluence 6 数据库整合有关你数据库的大小写敏感问题

    'Collation' 是数据如何被存储和比较的规则.大小写是否敏感是有关字符集设置的一个方面.其他大小写敏感的方面有 kana (Japanese script)和宽度(单字节对比双字节长度). 设 ...

  5. Linux用户、用户组、文件权限学习笔记

    最近打算更仔细学习一下linux操作系统.先是恶补了一下用户.用户组.文件权限这三样比较重要的知识.学习这几样东西,得先掌握linux的权限系统相关知识.linux的权限系统主要是由用户.用户组和权限 ...

  6. Python基础之面向对象的软件开发思路

    当我们来到生产环境中的时候,对一个软件需要开发的时候,刚开始也可能会懵逼,挝耳挠腮.不知从何下手,其 实,大家也不要苦恼,这是大多数程序员都会遇到的问题.那么,我们就要想一想了,既然大家都会这样,到低 ...

  7. Git使用四:查看工作状态和历史提交

    查看当前的工作状态:git status On branch master:现在位于master分支里面nothing to commit, working tree clean:没有需要提交的文件, ...

  8. tomcat启动报错 关键字:java.lang.NoClassDefFoundError和 java.lang.ClassNotFoundExceeption

    启动tomcat时报错情况如下图所示:实际上就是依赖的bean出错,百度上很多方法都说是tomcat没有部署正确,项目-->右键----->proterties----->Targe ...

  9. 基于nginx的WebSocket反向代理

    系统:windows 版本:nginx 1.4.5 配置内容: location ~ \.do$ {             proxy_pass   http://192.168.20.102:80 ...

  10. 步步为营-78-新闻展示(Ajax+Json+easyUI)

    Json:JavaScript Object Notation 1.1 Json对象的接收处理 <!DOCTYPE html> <html xmlns="http://ww ...