问题标签 [boost-regex]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
c++ - 正则表达式和增强。不使用简单的正则表达式
以下是我的以下代码
它总是输出没有匹配项。
我确定正则表达式应该可以工作。
我用了这个例子
http://onlamp.com/pub/a/onlamp/2006/04/06/boostregex.html?page=3
c++ - 为什么 boost regex 会耗尽堆栈空间?
这会产生:
编译
编辑
我的平台:
c++ - 如何将编译的正则表达式(std::regex)保存/序列化到文件中?
我使用<regex>
的是 Visal Studio 2010。我知道当我创建正则表达式对象时,它会被编译。没有像其他语言和库那样的编译方法,但我认为它是这样工作的,对吗?
我需要将大量编译的正则表达式存储在一个文件中,这样我就可以得到一块内存块并得到我编译的正则表达式。
我不知道该怎么做。我发现在 PCRE 中它是可能的,但它是 Linux 库。有一个 Windows [版本2,但它已有 3 年历史,我想使用更高级的方法(Windows 版本中没有 c++ 包装器)。
那么是否可以使用 savestd:regex
或boost::regex
(它是一样的权利?)作为一块内存,然后简单地重用它?
或者是否有其他简单的 Windows 库允许这样做?
编辑: 感谢您的出色回答。我将简单地检查将正则表达式存储为字符串是否足够,然后如果它仍然很慢,我将对其进行测试并将其与这个旧的 PCRE 库进行比较。
c++ - boost::regex_replace中两个参数格式函数的问题
我在boost::regex_replace
. 我可以调用它的一个参数版本,但不能调用两个参数:
其中repl_quot
定义为
以上工作,但我真的不想使用那个静态变量,所以我尝试了我认为是可接受的两个参数替代版本:
但是 regex_replace 不会接受这个(一个复杂的编译器错误)。我正在尝试根据Boost::Regex
文档中的以下内容使用两个参数版本:
模板 basic_string regex_replace(const basic_string& s, const basic_regex& e, Formatter fmt, match_flag_type flags = match_default);
要求类型 Formatter 必须是...一个从函数调用计算替换字符串的一元、二元或三元仿函数:要么是 fmt(what),它必须返回一个 char_type 的容器以用作替换文本,要么是 fmt (what, out) 或 fmt(what, out, flags),两者都将替换文本写入 *out,然后返回新的 OutputIterator 位置。在每种情况下,代表找到的匹配项的 match_results 对象是什么。
已经多次请求编译器错误消息,所以这里是(小心你要求的):
c:\boost\boost\regex\v4\regex_format.hpp 在成员函数`OutputIter boost::re_detail::format_functor_container::operator()(const Match&, OutputIter, boost::regex_constants::match_flag_type, const Traits&) [with OutputIter = boost::re_detail::string_out_iterator, std::allocator >>, Container = const std::string&(*)(const boost::smatch&, std::string&), Match = boost::match_results<__gnu_cxx:: __normal_iterator, std::allocator > >, std::allocator, std::allocator > > > > >, Traits = boost::regex_traits_wrapper > >]':
356 c:\boost\boost\regex\v4\match_results.hpp 从 `OutputIterator boost::match_results::format(OutputIterator, Functor, boost::regex_constants::match_flag_type, const RegexT&) 实例化re_detail::string_out_iterator, std::allocator >>, Functor = const std::string&(*)(const boost::smatch&, std::string&), RegexT = boost::basic_regex >>, BidiIterator = __gnu_cxx::__normal_iterator , std::allocator > >, Allocator = std::allocator, std::allocator > > > >]'
60 c:\boost\boost\regex\v4\regex_replace.hpp 从`OutputIterator boost::regex_replace(OutputIterator, BidirectionalIterator, BidirectionalIterator, const boost::basic_regex&, Formatter, boost::regex_constants::match_flag_type) [with OutputIterator = boost::re_detail::string_out_iterator, std::allocator >>, BidirectionalIterator = __gnu_cxx::__normal_iterator, std::allocator >>, traits = boost::regex_traits >, charT = char, Formatter = const std::string&(* )(const boost::smatch&, std::string&)]'
80 c:\boost\boost\regex\v4\regex_replace.hpp 从`std::basic_string, std::allocator<_T2> > boost::regex_replace(const std::basic_string, std::allocator<_T2> > &, const boost::basic_regex&, Formatter, boost::regex_constants::match_flag_type) [with traits = boost::regex_traits >, charT = char, Formatter = const std::string&(*)(const boost::smatch&, std ::细绳&)]'
327 C:\Dev-Cpp\Examples\wordrad\xhtml_open.cpp 从这里实例化
第1064
begin' in
章boost::regex_traits_wrapper > > >*)this)->boost::re_detail::format_functor_container, std::allocator > >, std::allocator, std::allocator > > > > >, boost::regex_traits_wrapper > > > ::func',它是非类类型 `const std::string&(* const)(const boost::smatch&, std::string&)'第1064
end' in
章boost::regex_traits_wrapper > > >*)this)->boost::re_detail::format_functor_container, std::allocator > >, std::allocator, std::allocator > > > > >, boost::regex_traits_wrapper > > > ::func',它是非类类型 `const std::string&(* const)(const boost::smatch&, std::string&)'
c++ - Boost regex_replace 异常:“......抛出这个异常是为了防止“永恒”匹配......”偶尔被抛出
我正在使用 Boost.Regex(boost-1.42) 删除多行字符串的第一行(一个相当大的字符串,包含以 '\n' 结尾的多行)。
即使用 regex_replace 做类似于 s/(.*?)\n//
此代码引发以下异常:
有趣/恼人的是,这似乎不会发生在具有相同测试数据的测试程序中。关于为什么会发生这种情况和/或如何解决它的任何想法?
c++ - C++/Boost:编写更强大的 sscanf 替代品
我想用 C++ 编写一个函数来替换 C 的 sscanf,它将匹配项分配给迭代器。
基本上,我想要类似的东西:
确切的细节可能会有所不同,但你明白了。有什么实施想法吗?
到目前为止的选项以及迄今为止的问题:
- std::istringstream:没有用于匹配常量表达式的操纵器
- Boost.Regex:不确定这是否可行,而且它似乎比必要的复杂得多
- Boost.Spirit:不要认为这适用于动态生成的格式字符串,而且它似乎也比必要的更复杂
- sscanf:它可以工作,但是是非标准的,等等,并且使用它需要很多开销,因为参数的数量是在编译时确定的
c++ - 我的 C++ 正则表达式匹配有什么问题
我正在用 C++ 编写 robots.txt 解析器
这应该与名称为 * 的用户代理匹配,但它会返回所有数据
c++ - 如何使用 boost::iostreams 将 bash 脚本转换为 C++
我正在尝试使用 boost::iostreams 将以下 bash 代码转换为 C++:
我可以打开一个文件并解压缩它:
然后打开一个未压缩的文件:
现在我有点卡住了,所以这是我的问题:
1) 连接两个流的 boost::iostreams 解决方案是什么?
2) 如何通过正则表达式过滤器输出结果以模拟 grep/sed?
因此,我想要一个可以复制到 cout 的 istream:
使用Hamigaki 的 concatenate更新完整的解决方案:
c++ - 使用boost正则表达式从字符串中提取IP地址?
我想知道是否有人可以帮助我,我一直在寻找正则表达式示例,但我仍然无法理解它。
字符串如下所示:
“用户 JaneDoe,IP:12.34.56.78”
“用户 JohnDoe,IP:34.56.78.90”
我将如何制作与上述字符串匹配的表达式?
c++ - 正则表达式与 BoostRegex C++
嗨,我希望得到以下表达式的值: POLYGON(100 20, 30 40, 20 10, 21 21) 搜索 POLYGON(100 20, 30 40, 20 10, 21 21)
当我执行以下代码时,我得到了这个结果:
POLYGON(100 20, 30 40, 20 10, 21 21)
result = 100 20
r2 = 100
r2 = 20
r2 = , 21 21
r2 = 21
size = 7
我不知道为什么我没有获得中间值......
感谢您的帮助