Boost正则表达式,怎么提取网页中所有加粗的文字
Boost正则表达式,如何提取网页中所有加粗的文字?
要提取的内容如下:
我需要把这里面<strong>1</strong> <strong>2</strong> <strong>safd</strong> sdfsf <strong>aaa</strong> bbb 23 <strong>2324</strong> acc的加粗的文字提取出来,也就是要1 2 safd aaa……这些
问题:
1、怎么提取。
2、怎么一个个的输出,好像是要用regex_iterator,看了半天,不是太明白。
------解决方案--------------------
要提取的内容如下:
- HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> <strong>1</strong> <strong>2</strong> <strong>safd</strong> sdfsf <strong>aaa</strong> bbb 23 <strong>2324</strong> acc </body> </html>
我需要把这里面<strong>1</strong> <strong>2</strong> <strong>safd</strong> sdfsf <strong>aaa</strong> bbb 23 <strong>2324</strong> acc的加粗的文字提取出来,也就是要1 2 safd aaa……这些
问题:
1、怎么提取。
2、怎么一个个的输出,好像是要用regex_iterator,看了半天,不是太明白。
------解决方案--------------------
- C/C++ code
<strong>(.*?)</strong>
------解决方案--------------------
- C/C++ code
#include <boost/regex.hpp> #include <iostream> int main() { boost::regex::basic_regex reg("<strong>(.*?)</strong>"); char const* str = "<strong>1</strong> <strong>2</strong> <strong>safd</strong> sdfsf <strong>aaa</strong> bbb 23 <strong>2324</strong> acc"; boost::regex_iterator<char const*> iter(str, str + strlen(str), reg), end; for(; iter != end; ++iter) std::cout << iter->str() << std::endl; }