<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

        Regex search to extract float from string. Python(正则表达式搜索以从字符串中提取浮点数.Python)
        <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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Initialize Multiple Numpy Arrays (Multiple Assignment) - Like MATLAB deal()(初始化多个 Numpy 数组(多重赋值) - 像 MATLAB deal())
                  How to extend Python class init(如何扩展 Python 类初始化)
                  What#39;s the difference between dict() and {}?(dict() 和 {} 有什么区别?)
                  What is a wrapper_descriptor, and why is Foo.__init__() one in this case?(什么是 wrapper_descriptor,为什么 Foo.__init__() 在这种情况下是其中之一?)
                  Initialize list with same bool value(使用相同的布尔值初始化列表)
                  setattr with kwargs, pythonic or not?(setattr 与 kwargs,pythonic 与否?)
                    <bdo id='DV1qQ'></bdo><ul id='DV1qQ'></ul>

                      <tbody id='DV1qQ'></tbody>
                    <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>