关于Boost Regex的问题

beefliu 2014-03-10 11:48:44
有一段HTML语言
<div id="123" class="abc"></div>
我想用正则匹配出
id 123
class abc
这样一组数据
我定义了一个struct来存放这样一组数据

struct tag
{
string name;
string value;
};

定义一个函数来得到这样一个数据
vector<tag> get(const string& html)
{
//请问函数里面怎么实现
}
...全文
124 5 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
miliggate 2014-03-13
  • 打赏
  • 举报
回复
想起来了 if(!boost::regex_match(str,result,reg)) ;//这里就是出错
miliggate 2014-03-13
  • 打赏
  • 举报
回复
boost::regex reg("<div\\s\\"id=.+?\\" class=\\".+?\\">); boost::match_result<string::const_iterator> result=boost::regex_match(str,reg);(参数有点记不清楚了,差不多的) string name=boost::lexical_cast<string>(result[0].str()); string value=boost::lexical_cast<string>(result[1].str()); 具体百度boost.regex
赵4老师 2014-03-12
  • 打赏
  • 举报
回复
仅供参考:(尽管是VB6)
'此代码由“正则测试工具  v1.1.35”自动生成,请直接调用TestReg过程
Private Sub TestReg()
    Dim strData As String
    Dim reg As Object
    Dim matchs As Object, match As Object

    strData = "<div id=""123"" class=""abc""></div>"

    Set reg = CreateObject("vbscript.regExp")
    reg.Global = True
    reg.IgnoreCase = True
    reg.MultiLine = True
    reg.Pattern = "\<div (\w+)=""(\w+)"" (\w+)=""(\w+)""></div>"
    Set matchs = reg.Execute(strData)
    For Each match In matchs
        'Debug.Print match.Value
        Debug.Print match.SubMatches(0)
    Next
End Sub
beefliu 2014-03-11
  • 打赏
  • 举报
回复
100分啊‘大神们赶紧来
beefliu 2014-03-11
  • 打赏
  • 举报
回复
没人给解决下嘛

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧