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. mysql 定期删除表中无用数据

    MySQL5.1.x版本中引入了一项新特性EVENT,定期执行某些事物,这可以帮助我们实现定期执行某个小功能,不在依赖代码去实现. 我现在有一张表,这张表中的数据有个特点,每天都会有大量数据插入,但是 ...

  2. vue的单选框

  3. 【kafka】confluent_kafka重置offset

    之前写过两篇关于重置offset的博文,后来使用过程中都有问题. 经过各种尝试,终于找到了解决方案. 直接上代码: # coding=utf8 from confluent_kafka import ...

  4. codeforce 240E 最小树形图+路径记录更新

    最小树形图的路径是在不断建立新图的过程中更新的,因此需要开一个结构体cancle记录那些被更新的边,保存可能会被取消的边和边在旧图中的id 在朱刘算法最后添加了一个从后往前遍历新建边的循环,这可以理解 ...

  5. spring cloud 路由网关zuul的高可用

    Zuul的高可用非常关键,因为外部请求到后端微服务的流量都会经过Zuul.故而在生产环境中,我们一般都需要部署高可用的Zuul以避免单点故障. 笔者分两种场景讨论Zuul的高可用. Zuul客户端也注 ...

  6. 论文阅读笔记十三:The One Hundred Layers Tiramisu: Fully Convolutional DenseNets for Semantic Segmentation(FC-DenseNets)(CVPR2016)

    论文链接:https://arxiv.org/pdf/1611.09326.pdf tensorflow代码:https://github.com/HasnainRaz/FC-DenseNet-Ten ...

  7. 论文阅读笔记八:SegNet: A Deep Convolutional Encoder-Decoder Architecture for Image Segmentation (IEEE2017)

    原文链接:https://arxiv.org/pdf/1511.00561.pdf github(tensorflow):https://github.com/aizawan/segnet 基于Seg ...

  8. linux:安装Memcache并使用

    1.Linux安装Memcache : curl -O http://memcached.org/files/memcached-1.5.4.tar.gz 解压 2.启动Memcache: memca ...

  9. VMware 虚拟机 Ubuntu 系统执行 ifconfig 命令 eth0没有IP地址(intet addr、Bcast、Mask) 解决:UP BROADCAST MULTICAST 问题

    VMware 虚拟机 ifconfig没有net_addr地址.Bcast.Mask的解决方法 使用时间长的虚拟机,会莫名其妙的连接不上网 在终端中,使用ifconfig命令查看Ubuntu系统的IP ...

  10. 20165206 预备作业3 Linux安装及学习

    Linux的安装与学习 - 在自己笔记本上安装Linux操作系统 在安装虚拟机的过程中遇到了不少问题,但也都进行了尝试并得到了解决.首先是在安装VirtulBox的安装上,按照老师给的链接下载安装,不 ...