【发布时间】:2011-04-27 05:57:10
【问题描述】:
我是正则表达式的新手 - 我在 C++ 中使用 Poco 从字符串中提取 IP 地址并(尝试)将所有 IP 匹配项放入字符串向量中:
string result = tcpClient.receiveRaw();
RegularExpression re("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b");
RegularExpression::MatchVec matches;
re.match(result, 0, matches);
IPlist = result.substr(matches[1].offset, matches[1].length);
我认为最后一行不正确(不确定它是如何工作的)我正在尝试从该初始字符串中提取所有 IP 地址并将它们添加到字符串向量中。
【问题讨论】:
-
我不知道 Poco。但我建议查看 boost boost.org/doc/libs/1_46_1/libs/regex/doc/html/index.html 的正则表达式
-
@ChristianSeverin 请注意,您所做的每一次编辑都会将问题推到首页,并会产生很多噪音。如果您认为应该重新标记,请先在meta 上询问。
标签: c++ regex poco-libraries