久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

<legend id='AE2ZV'><style id='AE2ZV'><dir id='AE2ZV'><q id='AE2ZV'></q></dir></style></legend>

  • <tfoot id='AE2ZV'></tfoot>

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

        <bdo id='AE2ZV'></bdo><ul id='AE2ZV'></ul>
      <i id='AE2ZV'><tr id='AE2ZV'><dt id='AE2ZV'><q id='AE2ZV'><span id='AE2ZV'><b id='AE2ZV'><form id='AE2ZV'><ins id='AE2ZV'></ins><ul id='AE2ZV'></ul><sub id='AE2ZV'></sub></form><legend id='AE2ZV'></legend><bdo id='AE2ZV'><pre id='AE2ZV'><center id='AE2ZV'></center></pre></bdo></b><th id='AE2ZV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='AE2ZV'><tfoot id='AE2ZV'></tfoot><dl id='AE2ZV'><fieldset id='AE2ZV'></fieldset></dl></div>
      1. 有條件地替換字符串中的正則表達(dá)式匹配項(xiàng)

        Conditionally replace regex matches in string(有條件地替換字符串中的正則表達(dá)式匹配項(xiàng))
          1. <i id='JsyLE'><tr id='JsyLE'><dt id='JsyLE'><q id='JsyLE'><span id='JsyLE'><b id='JsyLE'><form id='JsyLE'><ins id='JsyLE'></ins><ul id='JsyLE'></ul><sub id='JsyLE'></sub></form><legend id='JsyLE'></legend><bdo id='JsyLE'><pre id='JsyLE'><center id='JsyLE'></center></pre></bdo></b><th id='JsyLE'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='JsyLE'><tfoot id='JsyLE'></tfoot><dl id='JsyLE'><fieldset id='JsyLE'></fieldset></dl></div>

              <tbody id='JsyLE'></tbody>
            <legend id='JsyLE'><style id='JsyLE'><dir id='JsyLE'><q id='JsyLE'></q></dir></style></legend>
                <bdo id='JsyLE'></bdo><ul id='JsyLE'></ul>

                1. <small id='JsyLE'></small><noframes id='JsyLE'>

                  <tfoot id='JsyLE'></tfoot>
                  本文介紹了有條件地替換字符串中的正則表達(dá)式匹配項(xiàng)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時(shí)送ChatGPT賬號(hào)..

                  我正在嘗試用不同的替換模式替換字符串中的某些模式.

                  I am trying to replace certain patterns in a string with different replacement patters.

                  示例:

                  string test = "test replacing "these characters"";
                  

                  我想要做的是將所有的 ' ' 替換為 '_',并將所有其他非字母或數(shù)字字符替換為空字符串.我創(chuàng)建了以下正則表達(dá)式,它似乎正確標(biāo)記化,但我不確定如何(如果可能)使用 regex_replace 執(zhí)行條件替換.

                  What I want to do is replace all ' ' with '_' and all other non letter or number characters with an empty string. I have the following regex created and it seems to tokenize correctly, but I am not sure how to (if possible) perform a conditional replace using regex_replace.

                  string test = "test replacing "these characters"";
                  regex reg("(\s+)|(\W+)");
                  

                  替換后的預(yù)期結(jié)果是:

                  string result = "test_replacing_these_characters";
                  

                  我不能使用 boost,這就是為什么我把它排除在標(biāo)簽之外.所以請(qǐng)不要回答包括提升.我必須用標(biāo)準(zhǔn)庫來做到這一點(diǎn).可能是不同的正則表達(dá)式可以實(shí)現(xiàn)目標(biāo),或者我只是堅(jiān)持做兩次.

                  I cannot use boost, which is why I left it out of the tags. So please no answer that includes boost. I have to do this with the standard library. It may be that a different regex would accomplish the goal or that I am just stuck doing two passes.

                  我不記得在我原來的正則表達(dá)式時(shí) w 中包含了哪些字符,在查找之后我進(jìn)一步簡化了表達(dá)式.同樣,目標(biāo)是任何匹配 s+ 的內(nèi)容都應(yīng)替換為 '_',任何匹配的 W+ 均應(yīng)替換為空字符串.

                  I did not remember what characters were included in w at the time of my original regex, after looking it up I have further simplified the expression. Again the goal is anything matching s+ should be replaced with '_' and anything matching W+ should be replaced with empty string.

                  推薦答案

                  C++ (0x, 11, tr1) 正則表達(dá)式 不要在每種情況下都確實(shí)有效(stackoverflow)(查找 此頁面 上的短語 regex 用于 gcc),因此最好使用 boost 一段時(shí)間.

                  The c++ (0x, 11, tr1) regular expressions do not really work (stackoverflow) in every case (look up the phrase regex on this page for gcc), so it is better to use boost for a while.

                  你可以試試你的編譯器是否支持所需的正則表達(dá)式:

                  You may try if your compiler supports the regular expressions needed:

                  #include <string>
                  #include <iostream>
                  #include <regex>
                  
                  using namespace std;
                  
                  int main(int argc, char * argv[]) {
                      string test = "test replacing "these characters"";
                      regex reg("[^\w]+");
                      test = regex_replace(test, reg, "_");
                      cout << test << endl;
                  }
                  

                  以上適用于 Visual Studio 2012Rc.

                  The above works in Visual Studio 2012Rc.

                  編輯 1:要在一次傳遞中替換兩個(gè)不同的字符串(取決于匹配),我認(rèn)為這在這里不起作用.在 Perl 中,這可以在計(jì)算的替換表達(dá)式(/e 開關(guān))中輕松完成.

                  Edit 1: To replace by two different strings in one pass (depending on the match), I'd think this won't work here. In Perl, this could easily be done within evaluated replacement expressions (/e switch).

                  因此,正如您已經(jīng)懷疑的那樣,您需要兩次通過:

                  Therefore, you'll need two passes, as you already suspected:

                   ...
                   string test = "test replacing "these characters"";
                   test = regex_replace(test, regex("\s+"), "_");
                   test = regex_replace(test, regex("\W+"), "");
                   ...
                  

                  編輯 2:

                  如果可以在 regex_replace 中使用 回調(diào)函數(shù) tr(),那么您可以修改那里的替換,例如:

                  If it would be possible to use a callback function tr() in regex_replace, then you could modify the substitution there, like:

                   string output = regex_replace(test, regex("\s+|\W+"), tr);
                  

                  tr() 做替換工作:

                   string tr(const smatch &m) { return m[0].str()[0] == ' ' ? "_" : ""; }
                  

                  問題就解決了.不幸的是,在某些 C++11 正則表達(dá)式實(shí)現(xiàn)中沒有這樣的重載,但是 Boost 有一個(gè).以下將與 boost 一起使用并使用一次傳遞:

                  the problem would have been solved. Unfortunately, there's no such overload in some C++11 regex implementations, but Boost has one. The following would work with boost and use one pass:

                  ...
                  #include <boost/regex.hpp>
                  using namespace boost;
                  ...
                  string tr(const smatch &m) { return m[0].str()[0] == ' ' ? "_" : ""; }
                  ...
                  
                  string test = "test replacing "these characters"";
                  test = regex_replace(test, regex("\s+|\W+"), tr);   // <= works in Boost
                  ...
                  

                  也許有一天這將適用于 C++11 或接下來的任何數(shù)字.

                  Maybe some day this will work with C++11 or whatever number comes next.

                  問候

                  rbo

                  這篇關(guān)于有條件地替換字符串中的正則表達(dá)式匹配項(xiàng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Why do two functions have the same address?(為什么兩個(gè)函數(shù)的地址相同?)
                  Why the initializer of std::function has to be CopyConstructible?(為什么 std::function 的初始化程序必須是可復(fù)制構(gòu)造的?)
                  mixing templates with polymorphism(混合模板與多態(tài)性)
                  When should I use the keyword quot;typenamequot; when using templates(我什么時(shí)候應(yīng)該使用關(guān)鍵字“typename?使用模板時(shí))
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標(biāo)準(zhǔn)庫)
                  gcc can compile a variadic template while clang cannot(gcc 可以編譯可變參數(shù)模板,而 clang 不能)
                    <legend id='yNfsk'><style id='yNfsk'><dir id='yNfsk'><q id='yNfsk'></q></dir></style></legend>

                      <bdo id='yNfsk'></bdo><ul id='yNfsk'></ul>
                        • <i id='yNfsk'><tr id='yNfsk'><dt id='yNfsk'><q id='yNfsk'><span id='yNfsk'><b id='yNfsk'><form id='yNfsk'><ins id='yNfsk'></ins><ul id='yNfsk'></ul><sub id='yNfsk'></sub></form><legend id='yNfsk'></legend><bdo id='yNfsk'><pre id='yNfsk'><center id='yNfsk'></center></pre></bdo></b><th id='yNfsk'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='yNfsk'><tfoot id='yNfsk'></tfoot><dl id='yNfsk'><fieldset id='yNfsk'></fieldset></dl></div>

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

                            <tbody id='yNfsk'></tbody>

                          1. <tfoot id='yNfsk'></tfoot>
                          2. 主站蜘蛛池模板: 久操福利 | 久久在线精品 | 日韩一级免费视频 | a在线观看| 免费看黄色录像 | 欧美性生交xxxxx久久久 | 黄色一级片视频 | 国产91丝袜在线播放 | 亚洲天堂网在线观看 | 亚洲天堂网在线观看 | 国产精品久久久国产盗摄 | 三a毛片 | 天天摸天天干 | 日韩av免费在线观看 | 国语对白做受69 | 成年在线观看 | 久久久久久久网站 | 日本久久久久久 | 日韩一级黄 | 91久久综合亚洲鲁鲁五月天 | 精品久久久久久 | 五月婷丁香 | 中文字幕在线网站 | 玖玖视频 | 在线观看91视频 | 伊人国产在线 | 欧美日韩在线观看视频 | 成年人免费在线视频 | 欧美自拍一区 | 成人中文字幕在线观看 | 亚洲欧美日韩精品 | 亚洲一区二区三区四区在线 | 日本少妇一区二区 | 福利片在线观看 | 欧美一级在线播放 | 日韩欧美在线一区 | 欧美国产综合 | av高清不卡| 性色av浪潮av | 欧美激情区 | 日韩有码av |