Article View: pl.comp.lang.python
Article #27333Re: biale znaki, jak nie usuwac
From: Bart Ogryczak
Date: Mon, 01 Mar 2010 13:24
Date: Mon, 01 Mar 2010 13:24
14 lines
1959 bytes
1959 bytes
On Feb 26, 8:56 pm, Skiner <printers.man...@gmail.com> wrote:
> #!/usr/bin/env python
> import re
> fp =open('index.php','r')
> fo =open('index_nowy.php', 'w')
> for line in fp.readlines():
> fo.write(re.sub(r'\w<?\w', '<php', line))
Po pierwsze '?' jest w regexpach znakiem specjalnym, czyli jak chcesz
literał, to musisz poprzedzić \.
Po drugie jeśli wykorzystujesz to samo wyrażenie regularne
wielokrotnie, to warto jest skompilować.
Po trzecie jest opcja re.MULTILINE, więc nie trzeba linia po linii.
Technical Details
Message-ID:
<9dd49b6b-b03c-4b9d-a491-95cb9101ceb3@15g2000yqi.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!news.nask.pl!news.nask.org.pl!newsfeed00.sul.t-online.de!t-online.de!border2.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!15g2000yqi.googlegroups.com!not-for-mailReferences:
<45715cb0-0501-4ece-ac73-a0daa2389b68@m37g2000yqf.googlegroups.com> <5fecbff0-ee66-4d27-9777-4ab708e126c6@e1g2000yqh.googlegroups.com> <a77e0555-3217-451f-9ead-fdea74823dce@o3g2000yqb.googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.rmf.pl!agh.edu.pl!news.agh.edu.pl!news.onet.pl!news.nask.pl!news.nask.org.pl!newsfeed00.sul.t-online.de!t-online.de!border2.nntp.dca.giganews.com!nntp.giganews.com!postnews.google.com!15g2000yqi.googlegroups.com!not-for-mail From: Bart Ogryczak <b.ogryczak@gmail.com> Newsgroups: pl.comp.lang.python Subject: Re: biale znaki, jak nie usuwac Date: Mon, 1 Mar 2010 05:24:14 -0800 (PST) Organization: http://groups.google.com Lines: 14 Message-ID: <9dd49b6b-b03c-4b9d-a491-95cb9101ceb3@15g2000yqi.googlegroups.com> References: <45715cb0-0501-4ece-ac73-a0daa2389b68@m37g2000yqf.googlegroups.com> <5fecbff0-ee66-4d27-9777-4ab708e126c6@e1g2000yqh.googlegroups.com> <a77e0555-3217-451f-9ead-fdea74823dce@o3g2000yqb.googlegroups.com> NNTP-Posting-Host: 94.100.112.225 Mime-Version: 1.0 X-Trace: posting.google.com 1267449854 15457 127.0.0.1 (1 Mar 2010 13:24:14 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 1 Mar 2010 13:24:14 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: 15g2000yqi.googlegroups.com; posting-host=94.100.112.225; posting-account=1kG_1AoAAADLEA3eucGvO2J-Uo4aPCW_ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/532.5 (KHTML, like Gecko) Chrome/4.1.249.1017 Safari/532.5,gzip(gfe),gzip(gfe) Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit