关于手机号码解析的python查询

问题描述 投票:0回答:1

构建一个python程序来解析excel数据转储中的移动号码并将其存储在不同的excel文件中。附加了数据转储文件。

  • 手机号码必须为10位数。
  • 手机号码可以从0或+91开始。
  • 手机号码必须以9或8或7开头。
  • 每个单元格可以有多个数字。存储每个单元格中用逗号分隔的数字。

我写了这段代码:

import xlrd
import string
import re

workbook = xlrd.open_workbook('Data_Dump.xlsx')
RE_phone = re.compile("^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$")


for num in range():
      row = sheet1.row(num)
      for index, col in enumerate(cols):
          value = txt[index] + num
          row.write(index, value)

它不起作用。我是python的新手。如果我可以被引导到正确的方向,那将是非常感激的。

Data_dump

WORKLOAD REPOSITORY report for 9531066111 "" 93979695025 "DB Name         DB Id    Instance     Inst Num Startup Time    Release     RAC" 7812107175 "------------ ----------- ------------ -------- --------------- ----------- ---" 84256569115
 9227901842 "DB Name         DB Id    Instance     Inst Num Startup Time    Release     RAC" 99868256926 "------------ ----------- ------------ -------- --------------- ----------- ---" 7400963376 "FXBPCU25       832272769 FXBPCU25            1 07-Sep-17 05:09 11.2.0.4.0  NO " +918347699241
DB Name         DB Id    Instance     Inst Num Startup Time    Release     RAC 9924737563 "------------ ----------- ------------ -------- --------------- ----------- ---" 90424664527 "FXBPCU25       832272769 FXBPCU25            1 07-Sep-17 05:09 11.2.0.4.0  NO " 7989819567 "" +918044534972
------------ ----------- ------------ -------- --------------- ----------- --- 9621573294 "FXBPCU25       832272769 FXBPCU25            1 07-Sep-17 05:09 11.2.0.4.0  NO " 97393021728 "" 7686655298 "Host Name        Platform                         CPUs Co
FXBPCU25       832272769 FXBPCU25            1 07-Sep-17 05:09 11.2.0.4.0  NO  9154788735 "" 92725176229 "Host Name        Platform                         CPUs Cores Sockets Memory(GB)" 7383491029 "---------------- -------------------------------- ---- ----- ------- ----------" +918797011444
 9851624456 "Host Name        Platform                         CPUs Cores Sockets Memory(GB)" 99693533430 "---------------- -------------------------------- ---- ----- ------- ----------" 70803267410 "CNDBFXCEDBZP32   Linux x86 64-bit                   48    24       2     504.04" +918493847175
Host Name        Platform                         CPUs Cores Sockets Memory(GB) 9548460187 "---------------- -------------------------------- ---- ----- ------- ----------" 2136681081 "CNDBFXCEDBZP32   Linux x86 64-bit                   48    24       2     504.04" 77771624611 "" +918190682906
---------------- -------------------------------- ---- ----- ------- ---------- 9659741698 "CNDBFXCEDBZP32   Linux x86 64-bit                   48    24       2     504.04" 2833516802 "" 74739981912 "              Snap Id      Snap Time      Sessions Curs
CNDBFXCEDBZP32   Linux x86 64-bit                   48    24       2     504.04 9356577429 "" 2530352533 "              Snap Id      Snap Time      Sessions Curs/Sess" 71708339213 "            --------- ------------------- -------- ---------" +918476374828
 90534131410 "              Snap Id      Snap Time      Sessions Curs/Sess" 2227188264 "            --------- ------------------- -------- ---------" 78676696414 "Begin Snap:     20863 21-Nov-17 07:30:17       390       9.1" +918173210559
              Snap Id      Snap Time      Sessions Curs/Sess 95866285811 "            --------- ------------------- -------- ---------" 2282829015 "Begin Snap:     20863 21-Nov-17 07:30:17       390       9.1" 75645053715 "  End Snap:     20865 21-Nov-17 08:30:27       407       9.3" +9188700462710
            --------- ------------------- -------- --------- 92834643112 "Begin Snap:     20863 21-Nov-17 07:30:17       390       9.1" 2979664736 "  End Snap:     20865 21-Nov-17 08:30:27       407       9.3" 8311151721 "   Elapsed:               60.18 (mins)" 09873786851
Begin Snap:     20863 21-Nov-17 07:30:17       390       9.1 99803000313 "  End Snap:     20865 21-Nov-17 08:30:27       407       9.3" 2676500467 "   Elapsed:               60.18 (mins)" 8007987452 "   DB Time:            1,027.15 (mins)" 09131216302
  End Snap:     20865 21-Nov-17 08:30:27       407       9.3 96771357614 "   Elapsed:               60.18 (mins)" 2373336198 "   DB Time:            1,027.15 (mins)" 8704823173 "" 07897784883
   Elapsed:               60.18 (mins) 93739714915 "   DB Time:            1,027.15 (mins)" 2070171929 "" 8401658894 "Load Profile                    Per Second   Per Transaction  Per Exec  Per Call" 09988292054
   DB Time:            1,027.15 (mins) 90708072216 "" 27670076410 "Load Profile                    Per Second   Per Transaction  Per Exec  Per Call" 8098494625 "~~~~~~~~~~~~~~~            ---------------   --------------- --------- ---------" 09569660095
 97676429417 "Load Profile                    Per Second   Per Transaction  Per Exec  Per Call" 24638433711 "~~~~~~~~~~~~~~~            ---------------   --------------- --------- ---------" 8795330346 "             DB Time(s):              17.1               0.2      0.00      0.00" 08660167276
Load Profile                    Per Second   Per Transaction  Per Exec  Per Call 95201194218 "~~~~~~~~~~~~~~~            ---------------   --------------- --------- ---------" 29970588012 "             DB Time(s):              17.1               0.2      0.00      0.00" 8492166077 "              DB CPU(s):               2.2               0.0      0.00      0.00" 07750674467
~~~~~~~~~~~~~~~            ---------------   --------------- --------- --------- 92169551519 "             DB Time(s):              17.1               0.2      0.00      0.00" 25859150013 "              DB CPU(s):               2.2               0.0      0.00      0.00" 8189001808 "      Redo size (bytes):      13,798,845.9         151,217.7" 09841181638
             DB Time(s):              17.1               0.2      0.00      0.00 99137908720 "              DB CPU(s):               2.2               0.0      0.00      0.00" 22827507314 "      Redo size (bytes):      13,798,845.9         151,217.7" 8885837529 "  Logical read (blocks):         237,897.7           2,607.1" 08931688819
              DB CPU(s):               2.2               0.0      0.00      0.00 96106266021 "      Redo size (bytes):      13,798,845.9         151,217.7" 29795864515 "  Logical read (blocks):         237,897.7           2,607.1" 85826732510 "          Block changes:          77,067.0             844.6" 06289783331
      Redo size (bytes):      13,798,845.9         151,217.7 93074623222 "  Logical read (blocks):         237,897.7           2,607.1" 7024764281 "          Block changes:          77,067.0             844.6" 82795089811 " Physical read (blocks):           4,615.7              50.6" 04062071652
  Logical read (blocks):         237,897.7           2,607.1 90042980523 "          Block changes:          77,067.0             844.6" 7721599992 " Physical read (blocks):           4,615.7              50.6" 89763447012 "Physical write (blocks):           4,771.9              52.3" 01333593193
          Block changes:          77,067.0             844.6 97011337724 " Physical read (blocks):           4,615.7              50.6" 7418435723 "Physical write (blocks):           4,771.9              52.3" 80319854613 "       Read IO requests:           4,055.5              44.4" 07605114724
 Physical read (blocks):           4,615.7              50.6 01990906619 "Physical write (blocks):           4,771.9              52.3" 7115271454 "       Read IO requests:           4,055.5              44.4" 87288211814 "      Write IO requests:           2,717.1              29.8" 03904820465
Physical write (blocks):           4,771.9              52.3 07447863537 "       Read IO requests:           4,055.5              44.4" +0010422710 "      Write IO requests:           2,717.1              29.8" 04719385078 "           Read IO (MB):              36.1               0.4" 01176342006
python excel loops for-loop xlsx
1个回答
0
投票

我尝试了你的正则表达式模式与一些虚拟数据及其工作。请提供有关XLSX文件的更多详细信息。

这是我做的:

import re
RE_phone = re.compile("^(\+91[\-\s]?)?[0]?(91)?[789]\d{9}$")
mobile_no = ["+919712345678","9712345678","971234567","09712345678","06712345678","6712345678"]
for each in mobile_no:
    if RE_phone.match(each):
        print(each, ": Valid", each[-10:])
    else:
        print(each, ": Invalid", 0) 
© www.soinside.com 2019 - 2024. All rights reserved.