• <bdo id='2PKus'></bdo><ul id='2PKus'></ul>
      1. <small id='2PKus'></small><noframes id='2PKus'>

      2. <legend id='2PKus'><style id='2PKus'><dir id='2PKus'><q id='2PKus'></q></dir></style></legend>

        <tfoot id='2PKus'></tfoot>

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

        Python - 正则表达式在括号之间获取数字

        Python - Regular expressions get numbers between parenthesis(Python - 正则表达式在括号之间获取数字)
        <i id='0dC43'><tr id='0dC43'><dt id='0dC43'><q id='0dC43'><span id='0dC43'><b id='0dC43'><form id='0dC43'><ins id='0dC43'></ins><ul id='0dC43'></ul><sub id='0dC43'></sub></form><legend id='0dC43'></legend><bdo id='0dC43'><pre id='0dC43'><center id='0dC43'></center></pre></bdo></b><th id='0dC43'></th></span></q></dt></tr></i><div id='0dC43'><tfoot id='0dC43'></tfoot><dl id='0dC43'><fieldset id='0dC43'></fieldset></dl></div>

        <small id='0dC43'></small><noframes id='0dC43'>

          <tfoot id='0dC43'></tfoot>

            <tbody id='0dC43'></tbody>
            1. <legend id='0dC43'><style id='0dC43'><dir id='0dC43'><q id='0dC43'></q></dir></style></legend>

                <bdo id='0dC43'></bdo><ul id='0dC43'></ul>
                  本文介绍了Python - 正则表达式在括号之间获取数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我需要帮助创建正则表达式来获取括号之间的数字当我的值介于单词PIC"和."之间时

                  I need help creating a Regex to get numbers between parenthesis when my values are between word "PIC" and the "."

                  我得到了这些记录,需要能够提取 () 之间的值

                  I got this records and need to be able to extract values between ()

                  PIC S9(02)V9(05).    I need this result "02 05"
                  PIC S9(04).          I need this result "04"
                  PIC S9(03).          I need this result "03"
                  PIC S9(03)V9(03).    I need this result "03 03" 
                  PIC S9(02)V9(03).    I need this result "02 03"
                  PIC S9(04).          I need this result "04"  
                  PIC S9(13)V9(03).    I need this result "13 03"
                  

                  我尝试了以下方法,但它不起作用.

                  I have try the below but it doesnt work.

                  s = "PIC S9(02)V9(05)."
                  m = re.search(r"([0-9]+([0-9]))", s)
                  print m.group(1)
                  

                  推荐答案

                  你可以使用 re.findall() 查找括号内的所有数字:

                  You can use re.findall() to find all numbers within the parenthesis:

                  >>> import re
                  >>> l = [
                  ...     "PIC S9(02)V9(05).",
                  ...     "PIC S9(04).",
                  ...     "PIC S9(03).",
                  ...     "PIC S9(03)V9(03).",
                  ...     "PIC S9(02)V9(03).",
                  ...     "PIC S9(04).",
                  ...     "PIC S9(13)V9(03)."
                  ... ]
                  >>> pattern = re.compile(r"((d+))")
                  >>> for item in l:
                  ...     print(pattern.findall(item))
                  ... 
                  ['02', '05']
                  ['04']
                  ['03']
                  ['03', '03']
                  ['02', '03']
                  ['04']
                  ['13', '03']
                  

                  其中 () 将匹配文字括号(需要用反斜杠转义,因为它们具有特殊含义).(d+) 是一个捕获组 匹配一个或多个数字.

                  where ( and ) would match the literal parenthesis (needed to be escaped with a backslash because of the special meaning they have). (d+) is a capturing group that would match one or more digits.

                  这篇关于Python - 正则表达式在括号之间获取数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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% 就足够了)

                    <bdo id='Xskzd'></bdo><ul id='Xskzd'></ul>
                      <tbody id='Xskzd'></tbody>
                    <legend id='Xskzd'><style id='Xskzd'><dir id='Xskzd'><q id='Xskzd'></q></dir></style></legend>

                      <tfoot id='Xskzd'></tfoot>

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

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