资源描述:
《数据处理和智能决策实验四》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、实验编号04实验名称数据分析实验目的和要求1、正则表达式练习实验题目:1、运行下列代码,学习split。的使用(1)strmg=训阿・gziscas・com・cnprint(string・sp1it('・'))print(string・splitC・'2))print(string・split('・?32)[1])程序运行结果截图如下:
2、»>.RESTART:C:/Users/Administrator/AppData/Local/Jwwsgziscas,com,cnJ「www?,'gziscas,,'com.cn
3、]gziscas、、、(2)str=Mhelloboy<[www・baidu・com]>byebye"print(str.split[")[1])
4、print(str.split(,v['')[1].split("]")[0])程序运行结果截图如下:IIRESTART:C:/Users/AdmiIww.baidu.com]>byebyeww.baidu.comII1\12、运行下列代码importretext=Mjgoodisahandsomeboy,heiscool,Clevelandsoon../1rege
5、x=rexompile(r,w*oow*1)print(regex.findall(text))程序运行结果截图如下:■l>>>RESTART:「jgoodS’cool/]■1»>13、运行下列代码姓名:牛超实验时间:201859学号:15406038班级:物联一班importretelNumber="SupposemyPhoneNo.is0535-1234567,yoursis010-12345678,hisis025-8765432l.,upattern=re.compile(r'(d{3,4})-(
6、d{7,8})*)index=0whileTrue:matchResult=pattem.search(telNumberJndex)#从指定位置开始匹配ifnotmatchResult:breakprintC-'*30)printC^uccess:1)foriinrange(3):printC^earchcontent:matchResult.group(i)/Startfrom:matchResult>start(i)/Endat:matchResult.end(i)/Itsspanis:matchR
7、esult.span(i))index=matchResult.end(2)#指定下次匹配的开始位置程序运行结果截图如下:»>RESTART:C:/Users/Administrator/AppData/Local/Programs/Python/Python36-32/5555.Success:Searchcontent:Searchcontent:Searchcontent:Success:Searchcontent:Searchcontent:Searchcontent:Success:Searchconte
8、nt:Searchcontent:Searchcontent:、、、I36)py0535-1234567Startfrom:24Endat:36Itsspanis:(24,0535Startfrom:24Endat:28Itsspanis:(24,28)1234567Startfrom:29Endat:36Itsspanis:(29,36)Itsspanis:(46spanis:•14(Itsspanis:(66,spanis:010-12345678Startfrom:46Endat:58010Startfrom
9、:46Endat:49Itsspan12345678Startfrom:50Endat:58Its025-87654321Startfrom:66Endat:78025Startfrom:66Endat:69Itsspan87654321Startfrom:70Endat:78Its4、写一段话,包含四个qq号,编写代码,查找岀所有qq号?代码如下:importreQQ='myQQNo.is123,yoursis156,55556,66385’pattern=re.compile(r'd+,)#d是匹配数字字符
10、[0-9]index=0whileTrue:match=pattem.search(QQ,index)ifnotmatch:breakprint(川30)printCfound:1)foriinrange(l):printC^q/.match.groupCi))index二match.end(O)程序运行结果截图如下:===============RESTA