- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我注意到 boost xpressive sregex 分配中的奇怪行为。请参阅下面的代码。第一个不起作用的代码片段有 sregex 有对象初步分配,然后在主表达式中使用。第二个运行良好的代码片段没有预先分配 sregex(除了最后一个主要的)。如果我错误地使用了 boost xpressive api,请告诉我。
无效的代码
mark_tag Value1(1), Value2(2), Value3(3), Value4(4), Value5(5), Value6(6), Value7(7);
boost::xpressive::sregex name,multicast,rtsp;
name = ( (Value1 = (+boost::xpressive::set[_w|_d|'-'|'_'|as_xpr(' ')]) ) >> ',' );
name1 =
( (Value2 = icase(as_xpr("mark1:") ) )
>> (Value3 = (+boost::xpressive::set[_d|'.']) )
>> ':'
>> (Value4 = (+boost::xpressive::set[_d]) ) >> optional(as_xpr(",")) );
name2 =
( (Value5 = icase(as_xpr("mark2:") ) )
>> (Value6 = (+boost::xpressive::set[_d|'.']) )
>> ':'
>> (Value7 = (+boost::xpressive::set[_d]) ) >> optional(as_xpr(",")) ) ;
boost::xpressive::sregex pt = bos
>> (
name
>> repeat<0,2>(
name1
|
name2)
)
>> eos;
boost::trim(string_to_parse);
smatch what;
if ( !regex_search(string_to_parse, what, pt)) {
std::stringstream ss;
ss << "Unable to parse: " << string_to_parse;
throw parse::MyException(ss.str());
}
std::string Value1_str = what[Value1]; // print them later
std::string Value2_str = what[Value2]; // print them later
std::string Value3_str = what[Value3]; // print them later
std::string Value4_str = what[Value4]; // print them later
std::string Value5_str = what[Value5]; // print them later
std::string Value6_str = what[Value6]; // print them later
std::string Value7_str = what[Value7]; // print them later
string_to_parse = NameX,mark1:192.168.1.100:5555,mark2:192.168.1.101:5556;
(解析失败) 意思是[<>]不包含任何值。
有效的代码
mark_tag Value1(1), Value2(2), Value3(3), Value4(4), Value5(5), Value6(6), Value7(7);
sregex pt = bos
>> (
( (Value1 = (+boost::xpressive::set[_w|_d|'-'|'_'|as_xpr(' ')]) ) >> ',' )
>> repeat<0,2>(
( (Value2 = icase(as_xpr("mark1:") ) ) >> (Value3 = (+boost::xpressive::set[_d|'.']) ) >> ':' >> (Value4 = (+boost::xpressive::set[_d]) ) >> optional(as_xpr(",")) )
|
( (Value5 = icase(as_xpr("mark2:") ) ) >> (Value6 = (+boost::xpressive::set[_d|'.']) ) >> ':' >> (Value7 = (+boost::xpressive::set[_d]) ) >> optional(as_xpr(",")) ) )
)
>> eos;
boost::trim(string_to_parse);
smatch what;
if ( !regex_search(string_to_parse, what, pt)) {
std::stringstream ss;
ss << "Unable to parse: " << string_to_parse;
throw parse::MyException(ss.str());
}
std::string Value1_str = what[Value1]; // print them later
std::string Value2_str = what[Value2]; // print them later
std::string Value3_str = what[Value3]; // print them later
std::string Value4_str = what[Value4]; // print them later
std::string Value5_str = what[Value5]; // print them later
std::string Value6_str = what[Value6]; // print them later
std::string Value7_str = what[Value7]; // print them later
string_to_parse = NameX,mark1:192.168.1.100:5555,mark2:192.168.1.101:5556;
(通过解析)
最佳答案
当您将模式与嵌套的正则表达式匹配时,您会得到嵌套的匹配结果。 This解释一切。
关于c++ - Boost Xpressive sregex 分配和捕获组问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16465628/
我想在我的 C++ 作业中使用 Boost.Xpressive,并将其包含在我的源代码中。但是整个boost头文件有70MB+,那么有没有只包含依赖文件的独立xpressive发行版? 最佳答案 使用
我正在尝试解析一种自定义语言(与 JSON 不太相似),我决定尝试使用 boost expressive,因为它看起来很有趣。 但是,当表达匹配失败时,它就失败了。有什么办法可以实现某种错误报告吗?就
假设我有一个像这样的 sregex 对象: boost::xpressive::sregex::compile("(?P\\w+) (?\\w+)!"); 尽管 xpressive 支持命名组,但我无
我正在使用 boost::xpressive 来解析我的文本文件。我想看看是否仅当该行以“#”开头(多次)。 我正在使用下面的代码 std::string str1 = "## this could
每次检测到匹配项时,我都试图将数据结构插入到向量中,但我什至在编译时都失败了。接下来是代码: #include #include #include using namespace boost::
我在尝试使用 boost::xpressive 时收到一长串编译警告;特别是当我使用 sregex_compiler 的 compile() 函数时。 我关注了 documentation并将这个小程
我无法使用 regex_match 函数来查找不区分大小写的匹配项。尽管 boost::xpressive::regex_constants::icase 是 defined并且我使用了一个强制转换(
我有一个字符串可以是"/""+""."或描述性名称 我正在尝试弄清楚如何使用正则表达式来检查字符串是否与上面的 3 个特殊字符(/+ 或 .)中的任何一个匹配 读了一些书后,我决定采用 boost::
我注意到 boost xpressive sregex 分配中的奇怪行为。请参阅下面的代码。第一个不起作用的代码片段有 sregex 有对象初步分配,然后在主表达式中使用。第二个运行良好的代码片段没有
Edit8:我已经首先为可能遇到相同问题的人发布了解决方案。 解决方案: 使用 = 分配正则表达式,而不是调用 () 运算符。工作正常。那是愚蠢的。 #include #include #incl
嗨 boost::xpressive 用户, 尝试使用 boost::xpressive 解析某些决策树时出现堆栈溢出错误。它似乎适用于达到一定大小的树,但在“大”树上失败,其中“大”似乎意味着大约
我有以下代码。 sregex rex = sregex::compile( "(\\w+) (\\w+)!" ); 如何得到“(\w+) (\w+)!”从雷克斯出来? 最佳答案 查看 document
我有一个 boost xpressive sregex 和语义 Action 等同于以下内容: Rule = ('[' >> (s1=!(set=')',']','>')))[some_op(as(s
我尝试用出色的 Boost.XPressive 编写一个 mustache 解析器来自杰出的 Eric Niebler。但由于这是我的第一个解析器,我不熟悉编译器编写者的“正常”方法和行话,经过几天的
我想在 VC 2008 中使用正则表达式,但是我不能使用 boost 库(或者至少是整个 boost 库)。 我看到 boost.xpressive 中的文件正在使用其他 boost 目录中的文件。
我正在使用 boost.xpressive 静态模板构建动态连接成最终表达式的正则表达式。 动态版本有一个可变宽度的重复,但由于在 int vector 中操作,我确实需要使用静态结构。 我确实需要创
似乎 boost::xpressive 没有提供 new 运算符的惰性评估版本,所以这个语义操作不会编译: using namespace boost::xpressive ; std::vector
我想在 C++ 中做一些正则表达式,所以我查看了 interwebz(是的,我是 C++ 的初学者/中级)并发现 this SO answer . 我真的不知道在 boost::regex 和 boo
我认为 boost 正则表达式引擎会比 boost::algorithm 更快 这个简单的测试表明算法大大击败了正则表达式引擎 这是整个测试程序 我错过了什么吗? #include "boost/al
我们使用 boost::xpressive 在 C++/ObjC 应用程序中处理正则表达式。自从更新到 Mac OS 10.6 后,我们发现编译时间非常长(在 Dual-Quad MacPro 上每个
我是一名优秀的程序员,十分优秀!