|
#include<deque>
#include<iostream>
#include<algorithm>
#include<boost/regex.hpp>
int main()
{
using namespace boost;
using namespace std;
regex expression("//s+href//s*=//s*/"([^/"]*)/"",regbase::normal|regbase::icase);
string s="<a href=/"index.html/"><img src=/"logo.gif/"></a>";
deque<string> result;
regex_split(
std::back_inserter(result),s,expression);
copy(result.begin(),result.end(),ostream_iterator<string>(cout,"/n"));
int c;
cin>>c;
return 0;
}
|
|
. (dot)
|
用来匹配任何一个字符,但不包括新行上的字符
|
|
*
|
闭包,任意有限次的自重复连接
|
|
+
|
有限次自重复连接,但至少出现一次
|
|
{}
|
指定可能的重复次数
|
|
例如:
ba* 匹配 b ba baa baaa等
ba+ 匹配 ba baa baaaaaaaaa等
ba{1,5} 匹配 ba baa baaa baaaa baaaaa
| |
|
/
|
转义字符,有很多用途,根据参数设置而变化,最常见的就是类似于c语言/的用法
|
|
/s
|
匹配空格
|
|
/w
|
匹配一个单词
|
|
/d
|
匹配数字
|
|
()
|
有两种用法:
1是合并的作用,例如(ab)*匹配ab abab ababab等
2是确定匹配,也就是说在()中的字符将被最终拆解出来
|
|
#include<deque>
#include<iostream>
#include<algorithm>
#include<boost/regex.hpp>
#include<vcl.h>
int main()
{
using namespace boost;
using namespace std;
TStringList* html=new TStringList();
html->LoadFromFile("D://1.htm");
regex expression("//s+width=([^/"]*)/s+",regbase::normal|regbase::icase);
DWORD start=GetTickCount();
for(int n=0;n<html->Count;n++)
{
string s=html->Strings[n].c_str();
deque<string> result;
regex_split(std::back_inserter(result),s,expression);
copy(result.begin(),result.end(),ostream_iterator<string>(cout,"/n"));
result.clear();
}
start=GetTickCount()-start;
delete html;
cout<<start;
int c;
cin>>c;
return 0;
}
|
204




被折叠的 条评论
为什么被折叠?



