<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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                  Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                    <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>