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

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

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

          <bdo id='qka19'></bdo><ul id='qka19'></ul>
      1. <tfoot id='qka19'></tfoot>
      2. 正则表达式搜索以从字符串中提取浮点数.Python

        时间:2023-08-30
        <legend id='ueogK'><style id='ueogK'><dir id='ueogK'><q id='ueogK'></q></dir></style></legend>

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

              <tbody id='ueogK'></tbody>

              <i id='ueogK'><tr id='ueogK'><dt id='ueogK'><q id='ueogK'><span id='ueogK'><b id='ueogK'><form id='ueogK'><ins id='ueogK'></ins><ul id='ueogK'></ul><sub id='ueogK'></sub></form><legend id='ueogK'></legend><bdo id='ueogK'><pre id='ueogK'><center id='ueogK'></center></pre></bdo></b><th id='ueogK'></th></span></q></dt></tr></i><div id='ueogK'><tfoot id='ueogK'></tfoot><dl id='ueogK'><fieldset id='ueogK'></fieldset></dl></div>
            1. <tfoot id='ueogK'></tfoot>
                  <bdo id='ueogK'></bdo><ul id='ueogK'></ul>
                  本文介绍了正则表达式搜索以从字符串中提取浮点数.Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  import re
                  
                  sequence = 'i have -0.03 dollars in my hand'
                  
                  m = re.search('(have )(-w[.]+)( dollarsw+)',sequence)
                  
                  print m.group(0)
                  print m.group(1)
                  print m.group(2)
                  

                  Looking for a way to extract text between two occurrences. In this case, the format is 'i have ' followed by - floats and then followed by ' dollarsw+'

                  How do i use re.search to extract this float ? Why don't the groups work this way ? I know there's something I can tweak to get it to work with these groups. any help would be greatly appreciated

                  I thought I could use groups with paranthesis but i got an eror

                  解决方案

                  -w[.]+ does not match -0.03 because [.] matches . literally because . is inside the [...].

                  w after dollars also prevent the pattern to match the sequence. There no word character after dollars.

                  Use (-?d+.d+) as pattern:

                  import re
                  
                  sequence = 'i have -0.03 dollars in my hand'
                  
                  m = re.search(r'(have )(-?d+.d+)( dollars)', sequence)
                  
                  print m.group(1) # captured group start from `1`.
                  print m.group(2) 
                  print m.group(3)
                  

                  BTW, captured group numbers start from 1. (group(0) returns entire matched string)

                  这篇关于正则表达式搜索以从字符串中提取浮点数.Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何使用Python在满足两个条件的数组中查找值 下一篇:Python:按字符的位置拆分字符串

                  相关文章

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

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

                • <legend id='DV1qQ'><style id='DV1qQ'><dir id='DV1qQ'><q id='DV1qQ'></q></dir></style></legend>

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

                  <tfoot id='DV1qQ'></tfoot>