[Boost]_[使用boost正则表达式查找所有字符串]
2014-04-21 18:47
561 查看
场景:
1.比如在html中查找出现过的<img>标签,好提取图片地址.
2.编译器不支持C++11标准时使用boost库是比较好的选择.
test_search.cpp
输出:
参考:
http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/boost_regex/ref/regex_search.html
1.比如在html中查找出现过的<img>标签,好提取图片地址.
2.编译器不支持C++11标准时使用boost库是比较好的选择.
test_search.cpp
#include <stdio.h> #include <string> #include <iterator> #include <boost/regex.hpp> #include <iostream> using namespace std; int main(int argc, char *argv[]) { std::string str("infoasdf123unil98oasdfa686^&*(432"); boost::regex e1("[0-9]+"); std::string::const_iterator start, end; start = str.begin(); end = str.end(); boost::match_results<std::string::const_iterator> what; boost::match_flag_type flags = boost::match_default; while(regex_search(start, end, what, e1, flags)) { cout << "finded number: " << string(what[0].first,what[0].second) << endl; start = what[0].second; } return 0; } //http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/boost_regex/ref/regex_search.html
输出:
finded number: 123 finded number: 98 finded number: 686 finded number: 432
参考:
http://www.boost.org/doc/libs/1_46_1/libs/regex/doc/html/boost_regex/ref/regex_search.html
相关文章推荐
- [Boost]_[使用boost正则表达式查找所有字符串]
- 使用boost正则表达式查找所有字符串
- 在c++Builder中使用boost正则表达式实现的查找double和int类型的字符串,并实现StringToInteger和StringToDouble函数
- PHP使用正则表达式查找替换字符串
- java 正则表达式查找某段字符串中所有小写字母开头的单词并统计次数,按出现次数排序
- Notepad++ 使用正则表达式查找替换字符串
- 在python中使用正则表达式查找可嵌套字符串组
- 在python中使用正则表达式查找可嵌套字符串组
- java使用正则表达式获取字符串中的所有英文单词或数字
- 使用Android Studio查找文件中含有中文字符串位置(正则表达式)
- 使用正则表达式删除一个字符串中特定两个字符之间的所有字符
- IOS--正则表达式的使用(字符串的查找和替换)
- DW 查找某字符串前的所有字符的正则表达式
- 字符串处理是许多程序中非常重要的一部分,它们可以用于文本显示,数据表示,查找键和很多目的.在Unix下,用户可以使用正则表达式的强健功能实现这些 目的,从Java1.4起,Java核心API就引入了java.util.regex程序包,它是一种有价值的基础
- 使用Android Studio查找文件中含有中文字符串位置(正则表达式)
- DW 查找某字符串前的所有字符的正则表达式
- java使用正则表达式查找包含的字符串示例
- 查找目录下的所有文件中是否含有某个字符串 :正则表达式、find、grep、xargs、awk、sed等
- [SQL Server]使用正则表达式来查找字符串
- PHP使用正则表达式查找替换字符串