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

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

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

        <tfoot id='v8CO8'></tfoot>

        python re.sub 组: umber 之后的数字

        python re.sub group: number after umber(python re.sub 组:umber 之后的数字)
        • <tfoot id='2Hfai'></tfoot>

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

                <legend id='2Hfai'><style id='2Hfai'><dir id='2Hfai'><q id='2Hfai'></q></dir></style></legend>
                1. <small id='2Hfai'></small><noframes id='2Hfai'>

                    <tbody id='2Hfai'></tbody>

                  本文介绍了python re.sub 组: umber 之后的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何将 foobar 替换为 foo123bar?

                  这不起作用:

                  >>> re.sub(r'(foo)', r'1123', 'foobar')
                  'J3bar'
                  

                  这行得通:

                  >>> re.sub(r'(foo)', r'1hi', 'foobar')
                  'foohibar'
                  

                  我认为当有 umber 之类的内容时,这是一个常见问题.谁能给我一个关于如何处理这个问题的提示?

                  I think it's a common issue when having something like umber. Can anyone give me a hint on how to handle this?

                  推荐答案

                  答案是:

                  re.sub(r'(foo)', r'g<1>123', 'foobar')
                  

                  文档的相关摘录:

                  除了字符转义和如上所述的反向引用,g 将使用子字符串由名为 name 的组匹配,如由 (?P...) 语法定义.g 使用对应的组号;g<2> 因此是等价于 2,但不是模棱两可的在诸如g<2>0之类的替换中.20将被解释为参考第 20 组,不是对第 2 组的引用后跟文字字符0".反向引用 g<0> 替换为匹配的整个子字符串回复.

                  In addition to character escapes and backreferences as described above, g will use the substring matched by the group named name, as defined by the (?P...) syntax. g uses the corresponding group number; g<2> is therefore equivalent to 2, but isn’t ambiguous in a replacement such as g<2>0. 20 would be interpreted as a reference to group 20, not a reference to group 2 followed by the literal character '0'. The backreference g<0> substitutes in the entire substring matched by the RE.

                  这篇关于python re.sub 组: umber 之后的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  env: python: No such file or directory(env: python: 没有这样的文件或目录)
                  How to evaluate environment variables into a string in Python?(如何在 Python 中将环境变量评估为字符串?)
                  Python - temporarily modify the current process#39;s environment(Python - 临时修改当前进程的环境)
                  Change current process environment#39;s LD_LIBRARY_PATH(更改当前进程环境的 LD_LIBRARY_PATH)
                  Reading and writing environment variables in Python?(在 Python 中读写环境变量?)
                  When to use sys.path.append and when modifying %PYTHONPATH% is enough(何时使用 sys.path.append 以及何时修改 %PYTHONPATH% 就足够了)

                  <tfoot id='Yf01b'></tfoot><legend id='Yf01b'><style id='Yf01b'><dir id='Yf01b'><q id='Yf01b'></q></dir></style></legend>

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

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

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

                              <tbody id='Yf01b'></tbody>