9.Boost之正则regex
来源:互联网 发布:游戏鼠标 知乎 编辑:程序博客网 时间:2024/05/22 00:33
1正则表达式,案例1(如果使用的boost库是64位的,要把VS设置成支持64位的,这样的化,才可以运行通过)
#include<boost/regex.hpp>
#include<locale>
#include<iostream>
#include<string>
usingnamespacestd;
voidmain()
{
//设置语言环境为:English
std::locale::global(std::locale("English"));
string str ="chinaen8Glish";
boost::regexexpr("\\w+\\d\\u\\w+");//d代表数字,
//匹配就是1,不匹配就是0
cout <<boost::regex_match(str,expr) <<endl;
cin.get();
//运行结果为:1
}
2.通过正则取出匹配到的每部分
#include<boost/regex.hpp>
#include<locale>
#include<iostream>
#include<string>
usingnamespacestd;
voidmain()
{
std::locale::global(std::locale("English"));
stringstr ="chinaen8Glish9abv";
//d代表数字
boost::regexexpr("(\\w+)\\d(\\w+)");
boost::smatchwhat;
//按照表达式检索
if (boost::regex_search(str,what,expr))
{
cout <<what[0] <<endl;//这里是字符串本身
cout <<what[1] <<endl;//这里截取的字符串的第一部分
cout <<what[2] <<endl;//这里截取的字符串的第二部分
}
else
{
cout <<"检索失败";
}
cin.get();
}
运行结果:
3.通过正则表达式将正则中的数字编成指定的字符串。
#include<boost/regex.hpp>
#include<locale>
#include<iostream>
#include<string>
usingnamespacestd;
voidmain()
{
string str ="chinaen8 Glish9abv";
boost::regexexpr("\\d");//d代表数字,
string kongge ="______";
std::cout << boost::regex_replace(str,expr,kongge) <<endl;
cin.get();
}
运行结果:
- 9.Boost之正则regex
- Boost::regex之正则表达式
- Boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- !!! boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- (搬运工)Boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- boost库之正则表达式regex
- Boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- Boost学习之正则表达式--regex
- 正则表达式 boost Regex
- boost - regex 正则表达式
- leetCode: same tree
- HDOJ题目4985Little Pony and Permutation(置换群)
- 7.Boost之thread
- 8.Boost之unordered_set
- POJ 2400 KM最小权匹配+输出所有配对方案
- 9.Boost之正则regex
- python pip通过本地目录安装相关程序包
- 1Boost之TCP,Client and Server
- 致我的未来
- 分布式文件系统MFS、Ceph、GlusterFS、Lustre的比较
- 青劲草(http://www.caoqq.net)
- linux基础-"[Errno -3] Error performing checksum" yum 报错
- 打开PS6报错
- Start.学习记录的开始