文档介绍:Python正则基本说明之前讲过关于Python正则的,都是理论的东西,现在讲讲Python正则re模块。导入re模块:importre 查看帮助文档: 下面就是输出的帮助文档:Supportforregularexpressions(RE).-bitandUnicodestrings;,like"A","a",or"0",arethesimplestregularexpressions;,solastmatchesthestring'last'.Thespecialcharactersare:"."Matchesanycharacterexceptanewline."^"Matchesthestartofthestring."$"Matchestheendofthestringorjustbeforethenewlineattheendofthestring."*"Matches0ormore(greedy)."+"Matches1ormore(greedy)repetitionsoftheprecedingRE."?"Matches0or1(greedy)oftheprecedingRE.*?,+?,??Non-greedyversionsofthepreviousthreespecialcharacters.{m,n}MatchesfrommtonrepetitionsoftheprecedingRE.{m,n}?Non-greedyversionoftheabove."\\"Eitherescapesspecialcharactersorsignalsaspecialsequence.//FROMTHISWEBSITE:[]"^"plementingset."|"A|B,createsanREthatwillmatcheitherAorB.(...).(?iLmsux)SettheI,L,M,S,U,orXflagfortheRE(seebelow).(?:...)Non-groupingversionofregularparentheses.(?P<name>...)essiblebyname.(?P=name)Matchesthetextmatchedearlierbythegroupnamedname.(?#...)Acomment;ignored.(?=...)Matchesif...matchesnext,butdoesn'tconsumethestring.(?!...)Matchesif...doesn'tmatchnext.(?<=...)Matchesifprecededby...(mustbefixedlength).(?<!...)Matchesifnotprecededby...(mustbefixedlength).(?(id/name)yes|no)Matchesyespatternifthegroupwithid/namematched,the(optional)"\\",thentheresultingREwillmatchthesecondcharacter.\numberMatchesthecontents