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 ...
随机推荐
- list_test
#! -*- coding:utf-8 -*-"""len() ,len(list)方法返回列表元素个数,list -- 要计算元素个数的列表,返回值,返回列表元素个数元 ...
- Confluence 6 识别系统属性
Confluence 支持一些可以从 Java 系统属性中配置的配置参数和调试(debugging )设置.系统属性通常是使用 -D 为参数选项,这个选项是 Confluence 在运行后设置到 JV ...
- python之内置模块random(转载)
转载自http://www.cnblogs.com/wcwnina/p/9281334.html random.seed(a=None, version=2) # 初始化伪随机数生成器,若种子a相同, ...
- 3790:最短路径问题(HDU)
Problem Description 给你n个点,m条无向边,每条边都有长度d和花费p,给你起点s终点t,要求输出起点到终点的最短距离及其花费,如果最短距离有多条路线,则输出花费最少的. Inp ...
- 1709: Fire or Retreat(zzuli)
水题,哎,可是第一次是因为编译错了,vs不知咋了,无奈: 后面几次又因为类型用了int错了,痛苦: 题目描述 在与科技水平远胜于我们的外星人的战斗最后,我们能够用来对外星装甲造成伤害的武器只剩下了…… ...
- LeetCode(73):矩阵置零
Medium! 题目描述: 给定一个 m x n 的矩阵,如果一个元素为 0,则将其所在行和列的所有元素都设为 0.请使用原地算法. 示例 1: 输入: [ [1,1,1], [1,0,1], ...
- py4测试题
1.8<<2等于? 32 2.通过内置函数计算5除以2的余数 print(divmod(5,2))------>1 3.s=[1,"h",2,"e&qu ...
- Vuex状态管理模式的面试题及答案
转载:点击查看原文 1.vuex有哪几种属性? 答:有五种,分别是 State. Getter.Mutation .Action. Module 2.vuex的State特性是? 答: 一.Vuex就 ...
- CTPN项目部分代码学习
上次拜读了CTPN论文,趁热打铁,今天就从网上找到CTPN 的tensorflow代码实现一下,这里放出大佬的github项目地址:https://github.com/eragonruan/text ...
- HDU 1452 Happy 2004(因数和+费马小定理+积性函数)
Happy 2004 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...