boost 正则表达式 regex
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的更多相关文章
- 转:C++ Boost/tr1 Regex(正则表达式)快速指南
C++ Boost/tr1 Regex(正则表达式)快速指南 正则表达式自Boost 1.18推出,目前已经成为C++11(tr1)的标准部分. 本文以Boost 1.39正则表达式为基础,应该广泛适 ...
- (四)boost库之正则表达式regex
(四)boost库之正则表达式regex 正则表达式可以为我们带来极大的方便,有了它,再也不用为此烦恼 头文件: #include <boost/regex.hpp> 1.完全匹配 std ...
- Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答
Boost正则表达式库regex常用search和match示例 - 编程语言 - 开发者第2241727个问答 Boost正则表达式库regex常用search和match示例 发表回复 Boo ...
- C#正则表达式Regex常用匹配
使用Regex类需要引用命名空间:using System.Text.RegularExpressions; 利用Regex类实现验证 示例1:注释的代码所起的作用是相同的,不过一个是静态方法,一个是 ...
- C#正则表达式Regex类的用法
C#正则表达式Regex类的用法 更多2014/2/18 来源:C#学习浏览量:36891 学习标签: 正则表达式 Regex 本文导读:正则表达式的本质是使用一系列特殊字符模式,来表示某一类字符串, ...
- C#正则表达式Regex类
C#正则表达式Regex类的使用 C#中为正则表达式的使用提供了非常强大的功能,这就是Regex类.这个包包含于System.Text.RegularExpressions命名空间下面,而这个命名空间 ...
- VS2010中使用boost正则表达式库
1.下载boost库.http://www.boost.org/ 我下载的是boost_1_51_0版本.放在D:\opensource\boost_1_51_0. 2.编译boost库. 执 ...
- 请写出正则表达式(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 ...
- Python 正则表达式(RegEx)
版权所有,未经许可,禁止转载 章节 Python 介绍 Python 开发环境搭建 Python 语法 Python 变量 Python 数值类型 Python 类型转换 Python 字符串(Str ...
随机推荐
- C#操作excel(多种方法比较)
1.用查询表的方式查询并show在数据集控件上. public static string strCon = " Provider = Microsoft.Jet.OLEDB.4.0 ; D ...
- Penetration testing _internal & wireless Penetration Testing
第一部分 渗透测试步骤 ---参考资料 Ethical Hacking: The Value of Controlled Penetration Tests 下载地址 链接:https://pa ...
- sqlmap实例文档
sqlmap 手册参数整理文档 1.--data sqlmap -u "http://www.target.com/vuln.php" --data="id=1" ...
- Little Red Riding Hood
问题 : Little Red Riding Hood 时间限制: 1 Sec 内存限制: 1280 MB 题目描述 Once upon a time, there was a little gir ...
- 简单(基本)的风光摄影照片后期处理-新手教程-ps照片后期基本处理
前言 Photoshop虽然不是万能的,但缺少Photoshop却是万万不能的!风光摄影不是一个记录过程,做到的不能仅仅是“拍到了”,我觉得应该是一个创作的过程,特别是在后期处理的过程中,创作意味更浓 ...
- CentOS安装jdk的三种方法
方法一:手动解压JDK的压缩包,然后设置环境变量 方法二:用yum安装JDK,(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的 ...
- linux下配置docker和splash(图文)
所需要环境:ubuntu16.04 第一步用:sudo apt install docker.io 第二步:完成后查看一下有没有成功 命令:docker -v,如果是输入错了写成了大V他会提示你有哪些 ...
- 20165328 学习基础和C语言基础调查
一.技能学习经验: 1.你有什么技能比大多数人(超过90%以上)更好: 我算是一个普通人,没什么特别的才能,如果硬要说有什么技能比其他人较好的话,我想大概是快速阅读的能力吧,我能以很快的速度 ...
- jquery源码 整体架构
一.对外提供接口 对外提供了jQuery. //可以通过jQuery或者$来找到jQuery (function(window,undefined){ //(21,94) 定义了一些变量和函数 jQu ...
- stl测试
以下测试都在学校电脑进行 我觉得应该比考试机器慢一点.. 1.map map的速度测出来和放入数值大小有很大关系 比如 #include <bits/stdc++.h> using nam ...