Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #38864

how to right the regular expression ?

Path csiph.com!usenet.pasdenom.info!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <mailtomanage@163.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.017
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'output': 0.04; 'attribute': 0.05; '-*-': 0.07; 'utf-8': 0.07; '8bit%:30': 0.09; 'coding:': 0.09; 'output?': 0.16; 'subject:expression': 0.16; 'subject:regular': 0.16; 'skip:p 30': 0.20; 'import': 0.21; 'message-id:@163.com': 0.22; 'skip:" 20': 0.26; '(most': 0.27; 'skip:( 20': 0.28; '8bit%:89': 0.29; 'skip:& 10': 0.29; 'subject: ?': 0.30; 'code': 0.31; 'file': 0.32; 'print': 0.32; 'received:220.181.13': 0.33; 'traceback': 0.33; 'to:addr:python- list': 0.33; 'code:': 0.33; 'skip:( 30': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'url:ip addr': 0.62; 'here': 0.65; '8bit%:100': 0.70; 'url:177': 0.84; 'url:202': 0.84; '8bit%:54': 0.91; '8bit%:56': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=Received:Date:From:To:Subject:Content-Type: MIME-Version:Message-ID; bh=xFMju1JyT5b30kf/ZJt3m1YHhHfj+k8XiCCA EaDAoeQ=; b=LNm2MmA+JTXlsGsielGxsBvKFYaoeR9SwlpAtHuP8nCcI4ujaytz ++GRM9n725fW00HS7HeAh6klv8YTCm0CpFXdzjIamCE0PZdaqDGGb06oIoSwrLqq 2IsnGjCYV65F3Q7Xv505Dvnh5r9WqQ/coKgod7DAXH4j0h/3n/9mZ9k=
X-Originating-IP [1.89.180.69]
Date Thu, 14 Feb 2013 22:13:35 +0800 (CST)
From python <mailtomanage@163.com>
To python-list@python.org
Subject how to right the regular expression ?
X-Priority 3
X-Mailer Coremail Webmail Server Version SP_ntes V3.5 build 20130124(21453.5226.5222) Copyright (c) 2002-2013 www.mailtech.cn 163com
X-CM-CTRLDATA YaVH1WZvb3Rlcl9odG09MzQwNTo4MQ==
Content-Type multipart/alternative; boundary="----=_Part_61445_1500233956.1360851215316"
MIME-Version 1.0
X-CM-TRANSID D8GowGB5H0EP8RxR5jVCAA--.21403W
X-CM-SenderInfo hpdlz3xrpd0tljh6il2tof0z/1tbisB3DPFEAAXlD7wABsW
X-Coremail-Antispam 1U5529EdanIXcx71UUUUU7vcSsGvfC2KfnxnUU==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1764.1360852148.2939.python-list@python.org> (permalink)
Lines 121
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1360852148 news.xs4all.nl 6883 [2001:888:2000:d::a6]:48726
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:38864

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

my tv.txt is :  
http://202.177.192.119/radio5 香港电台第五台(可于Totem/VLC/MPlayer播放)  
http://202.177.192.119/radio35 香港电台第五台(DAB版,可于Totem/VLC/MPlayer播放)  
http://202.177.192.119/radiopth 香港电台普通话台(可于Totem/VLC/MPlayer播放)  
http://202.177.192.119/radio31 香港电台普通话台(DAB版,可于Totem/VLC/MPlayer播放)  
octoshape:rthk.ch1 香港电台第一台(粤)  
octoshape:rthk.ch2 香港电台第二台(粤)  
octoshape:rthk.ch6 香港电台普通话台  
octoshape:rthk.ch3 香港电台第三台(英)  
  
  
what i want to get the result is   
1group is  http://202.177.192.119/radio5  2group is  香港电台第五台 3group is  (可于Totem/VLC/MPlayer播放)  
1group is  http://202.177.192.119/radio35  2group is  香港电台第五台 3group is  (DAB版,可于Totem/VLC/MPlayer播放)  
1group is  http://202.177.192.119/radiopth  2group is  香港电台普通话台 3group is  (可于Totem/VLC/MPlayer播放)  
1group is  http://202.177.192.119/radio31  2group is  香港电台普通话台 3group is  (DAB版,可于Totem/VLC/MPlayer播放)  
1group is  octoshape:rthk.ch1  2group is  香港电台第一台 3group is  (粤)  
1group is  octoshape:rthk.ch2  2group is  香港电台第二台 3group is  (粤)  
1group is  octoshape:rthk.ch6  2group is  香港电台普通话台 3group is  none  
1group is  octoshape:rthk.ch3  2group is  香港电台第三台 3group is  (英)  
  
here is my code:  
# -*- coding: utf-8 -*-  
import re  
rfile=open("tv.txt","r")  
pat='([a-z].+?\s)(.+)(\(.+\))'  
for  line in  rfile.readlines():  
    Match=re.match(pat,line)  
    print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group is ",Match.group(3)  
rfile.close()  
  
the output is :  
1group is  http://202.177.192.119/radio5  2group is  香港电台第五台 3group is  (可于Totem/VLC/MPlayer播放)  
1group is  http://202.177.192.119/radio35  2group is  香港电台第五台 3group is  (DAB版,可于Totem/VLC/MPlayer播放)  
1group is  http://202.177.192.119/radiopth  2group is  香港电台普通话台 3group is  (可于Totem/VLC/MPlayer播放)  
1group is  http://202.177.192.119/radio31  2group is  香港电台普通话台 3group is  (DAB版,可于Totem/VLC/MPlayer播放)  
1group is  octoshape:rthk.ch1  2group is  香港电台第一台 3group is  (粤)  
1group is  octoshape:rthk.ch2  2group is  香港电台第二台 3group is  (粤)  
1group is   
Traceback (most recent call last):  
  File "tv.py", line 7, in <module>  
    print "1group is ",Match.group(1),"2group is ",Match.group(2),"3group is ",Match.group(3)  
AttributeError: 'NoneType' object has no attribute 'group'  
  
how to revise my code to get the output? 

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

how to right the regular expression ? python <mailtomanage@163.com> - 2013-02-14 22:13 +0800

csiph-web