【发布时间】:2026-01-15 12:05:01
【问题描述】:
我有两个字符串,我需要用boost::regex 将它们解析为一个。为了实现这一点,我需要将我的字符串粘在一些 boost::string_ref 之类的对象中,但是不允许进行额外分配。
换句话说,我需要这样的东西。
const char s1[] = "abcd<ht";
const char s2[] = "ml>giuya";
boost::regex e("<[^>]*>");
//this is what i'm looking for
auto glued_string = make_glued_string(s1, sizeof(s1)-1,
s2, sizeof(s2)-1);
boost::regex_iterator<glue_string::iterator>
it(glued_string.begin(), glued_string.end(), e,
boost::match_default | boost::match_partial);
所以问题是有没有合适的库或者我必须自己实现?谢谢。
【问题讨论】:
-
您似乎正在尝试使用正则表达式解析某种类似 HTML 的语法。请参考this answer.
-
谢谢,但这只是一个例子。我的任务确实需要正则表达式。
-
boost::range::join 应该可以工作(尽管我指出了错误的版本)。看到这个问题:*.com/questions/14366576/…
-
这个好像是我需要的,谢谢,我试试