久久久久久久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. 有條件地替換字符串中的正則表達式匹配項

        Conditionally replace regex matches in string(有條件地替換字符串中的正則表達式匹配項)
          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>
                  本文介紹了有條件地替換字符串中的正則表達式匹配項的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  限時送ChatGPT賬號..

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

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

                  示例:

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

                  我想要做的是將所有的 ' ' 替換為 '_',并將所有其他非字母或數(shù)字字符替換為空字符串.我創(chuàng)建了以下正則表達式,它似乎正確標記化,但我不確定如何(如果可能)使用 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,這就是為什么我把它排除在標簽之外.所以請不要回答包括提升.我必須用標準庫來做到這一點.可能是不同的正則表達式可以實現(xià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.

                  我不記得在我原來的正則表達式時 w 中包含了哪些字符,在查找之后我進一步簡化了表達式.同樣,目標是任何匹配 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) 正則表達式 不要在每種情況下都確實有效(stackoverflow)(查找 此頁面 上的短語 regex 用于 gcc),因此最好使用 boost 一段時間.

                  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.

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

                  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:要在一次傳遞中替換兩個不同的字符串(取決于匹配),我認為這在這里不起作用.在 Perl 中,這可以在計算的替換表達式(/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 正則表達式實現(xiàn)中沒有這樣的重載,但是 Boost 有一個.以下將與 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)于有條件地替換字符串中的正則表達式匹配項的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Why do two functions have the same address?(為什么兩個函數(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(我什么時候應(yīng)該使用關(guān)鍵字“typename?使用模板時)
                  Dependent name resolution amp; namespace std / Standard Library(依賴名稱解析命名空間 std/標準庫)
                  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. 主站蜘蛛池模板: 国产精品欧美一区二区三区不卡 | 伊人焦久影院 | 999热精品| 日本天堂一区二区 | 夜久久| 国产亚洲精品久久久久久牛牛 | 亚洲性视频 | 成人av播放 | 国产精品不卡一区 | 久久激情网 | 久久久久久国产精品久久 | 国产成人99久久亚洲综合精品 | 久久久.com| 国产激情网 | 在线视频久久 | 亚洲精品久久区二区三区蜜桃臀 | 色吧久久| 狼色网 | 九九热在线视频观看这里只有精品 | 日韩精品一区二区三区第95 | av毛片| 亚洲精品视频在线观看免费 | 成年人精品视频在线观看 | 韩日精品在线观看 | 国产精品久久久久久久久久三级 | 日韩在线免费视频 | 国产精品伦理一区二区三区 | 亚洲精品乱码久久久久久按摩观 | 国产精品美女久久久久 | 久久免费视频1 | 久久综合久色欧美综合狠狠 | 久久久www成人免费无遮挡大片 | 欧美亚洲网站 | 91免费观看视频 | 精品久久中文字幕 | 亚洲一区中文字幕在线观看 | 91免费观看视频 | 亚洲 欧美 日韩在线 | 欧美精品在线观看 | 91短视频网址 | 91天堂网|