• <small id='DMBqG'></small><noframes id='DMBqG'>

      <bdo id='DMBqG'></bdo><ul id='DMBqG'></ul>

    <tfoot id='DMBqG'></tfoot><legend id='DMBqG'><style id='DMBqG'><dir id='DMBqG'><q id='DMBqG'></q></dir></style></legend>
      <i id='DMBqG'><tr id='DMBqG'><dt id='DMBqG'><q id='DMBqG'><span id='DMBqG'><b id='DMBqG'><form id='DMBqG'><ins id='DMBqG'></ins><ul id='DMBqG'></ul><sub id='DMBqG'></sub></form><legend id='DMBqG'></legend><bdo id='DMBqG'><pre id='DMBqG'><center id='DMBqG'></center></pre></bdo></b><th id='DMBqG'></th></span></q></dt></tr></i><div id='DMBqG'><tfoot id='DMBqG'></tfoot><dl id='DMBqG'><fieldset id='DMBqG'></fieldset></dl></div>

      1. 在最外括号内查找字符串

        Find String Inside Outermost Parenthesis(在最外括号内查找字符串)
      2. <tfoot id='pmcZP'></tfoot>
        <legend id='pmcZP'><style id='pmcZP'><dir id='pmcZP'><q id='pmcZP'></q></dir></style></legend>
          <i id='pmcZP'><tr id='pmcZP'><dt id='pmcZP'><q id='pmcZP'><span id='pmcZP'><b id='pmcZP'><form id='pmcZP'><ins id='pmcZP'></ins><ul id='pmcZP'></ul><sub id='pmcZP'></sub></form><legend id='pmcZP'></legend><bdo id='pmcZP'><pre id='pmcZP'><center id='pmcZP'></center></pre></bdo></b><th id='pmcZP'></th></span></q></dt></tr></i><div id='pmcZP'><tfoot id='pmcZP'></tfoot><dl id='pmcZP'><fieldset id='pmcZP'></fieldset></dl></div>

            • <bdo id='pmcZP'></bdo><ul id='pmcZP'></ul>

                    <tbody id='pmcZP'></tbody>

                  <small id='pmcZP'></small><noframes id='pmcZP'>

                • 本文介绍了在最外括号内查找字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  假设我有一个包含多组括号和嵌套括号的字符串.我只想提取遇到的第一个括号中的字符串,包括它包含的任何嵌套括号.

                  Say that I have a string which contains both multiple sets and nesting of parenthesis. I want to extract only the string in the first parenthesis encountered, including whatever nested parenthesis it contains.

                  例如:

                  这(是(也许))一个测试(也许不是)

                  this (is(maybe)) a test (and maybe not)

                  我要提取:

                  是(也许)

                  我相信这可以在不使用正则表达式的情况下完成,通过它我可以轻松做到.

                  I believe this can be accomplished without the use of regexes, by which I can easily do it.

                  所以我的问题是如何在没有正则表达式的情况下实现这一点?

                  So my question is how can this be accomplished without regexes?

                  推荐答案

                  以免伪代码成为我自己使用标准算法回答这个问题的唯一答案.鉴于 const string foo{ "this (is(maybe)) a test (and may not)" } c++14 可以这样解决:

                  Lest pseudo code be the only answer I've taken it upon myself to answer this using standard algorithms. Given const string foo{ "this (is(maybe)) a test (and maybe not)" } c++14 can be used to solve like this:

                  const auto start = find(cbegin(foo), cend(foo), '(');
                  const auto finish = find_if(start, cend(foo), [count = 0](const char i) mutable {
                      if (i == '('){
                          count++;
                      }
                      else if (i == ')'){
                          count--;
                      }
                      return count <= 0; });
                  

                  从这里开始,如果 startfinish 都不是 cend(foo) 字符串是有效的,可以从 获得字符串(下一个(开始),完成)(现场示例).

                  From here, if both start and finish are not cend(foo) the string is valid and can be obtained from string(next(start), finish) (Live Example).

                  这可能是一个与 C++ 中一样好的解决方案.我想这只是一厢情愿的想法,有一些东西可以匹配括号并找到值.

                  It's possible that this is as good a solution as there is in C++. I guess it is just wishful thinking that there's something out there to match parentheses and find the value.

                  这篇关于在最外括号内查找字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
                  How should a size-limited stl-like container be implemented?(应该如何实现大小受限的 stl 类容器?)
                  Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
                  STL BigInt class implementation(STL BigInt 类实现)
                  Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
                  Move list element to the end in STL(在 STL 中将列表元素移动到末尾)

                    <legend id='3u8ZL'><style id='3u8ZL'><dir id='3u8ZL'><q id='3u8ZL'></q></dir></style></legend>

                          <bdo id='3u8ZL'></bdo><ul id='3u8ZL'></ul>
                            <tbody id='3u8ZL'></tbody>
                          <i id='3u8ZL'><tr id='3u8ZL'><dt id='3u8ZL'><q id='3u8ZL'><span id='3u8ZL'><b id='3u8ZL'><form id='3u8ZL'><ins id='3u8ZL'></ins><ul id='3u8ZL'></ul><sub id='3u8ZL'></sub></form><legend id='3u8ZL'></legend><bdo id='3u8ZL'><pre id='3u8ZL'><center id='3u8ZL'></center></pre></bdo></b><th id='3u8ZL'></th></span></q></dt></tr></i><div id='3u8ZL'><tfoot id='3u8ZL'></tfoot><dl id='3u8ZL'><fieldset id='3u8ZL'></fieldset></dl></div>
                        • <small id='3u8ZL'></small><noframes id='3u8ZL'>

                        • <tfoot id='3u8ZL'></tfoot>