Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.006 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'framework.': 0.07; 'subject:help': 0.07; 'python': 0.09; 'matched': 0.09; 'skip:r 50': 0.09; 'to:addr:comp.lang.python': 0.09; 'cc:addr:python- list': 0.10; 'expr.': 0.16; 'help?': 0.16; 'subject:required': 0.16; 'string': 0.17; 'wrote:': 0.17; 'python?': 0.20; 'wednesday,': 0.22; 'cc:2**0': 0.23; 'matching': 0.23; 'somebody': 0.23; "i've": 0.23; 'cc:no real name:2**0': 0.24; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'header :User-Agent:1': 0.26; 'replace': 0.27; 'regular': 0.27; 'received:209.85.212': 0.28; 'december': 0.32; "skip:' 20": 0.32; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'thanks': 0.34; 'text.': 0.35; 'received:209.85': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'where': 0.40; 'subject:-': 0.40; 'help': 0.40; 'urgent': 0.66; 'subject: & ': 0.67; 'online': 0.70; 'million': 0.72; 'otten': 0.84; 'received:209.85.212.56': 0.91 Newsgroups: comp.lang.python Date: Wed, 19 Dec 2012 05:41:47 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=182.178.4.117; posting-account=gL3NJgoAAABqumi65WD0uvB0Xp0lRXiO References: User-Agent: G2/1.0 X-Google-Web-Client: true X-Google-IP: 182.178.4.117 MIME-Version: 1.0 Subject: Re: Pattern-match & Replace - help required From: AT To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=ISO-8859-1 Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1355935196 news.xs4all.nl 6910 [2001:888:2000:d::a6]:38245 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:35137 On Wednesday, 19 December 2012 18:16:18 UTC+5, Peter Otten wrote: > AT wrote: > > > > > I am new to python and web2py framework. Need urgent help to match a > > > pattern in an string and replace the matched text. > > > > > > I've this string (basically an sql statement): > > > stmnt = 'SELECT taxpayer.id, > > > taxpayer.enc_name, > > > taxpayer.age, > > > taxpayer.occupation > > > FROM taxpayer WHERE (taxpayer.id IS NOT NULL);' > > > > > > The requirement is to replace it with this one: > > > r_stmnt = 'SELECT taxpayer.id, > > > decrypt(taxpayer.enc_name), > > > taxpayer.age, > > > taxpayer.occupation > > > FROM taxpayer WHERE (taxpayer.id IS NOT NULL);' > > > > > > Can somebody please help? > > > > > The pattern is '%s.enc_%s', and after matching this pattern want to change > > > it to 'decrypt(%s.enc_%s)' > > > > after = re.compile(r"(\w+[.]enc_\w+)").sub(r"decrypt(\1)", before) Thanks a million Can you recommend a good online book/tutorial on regular expr. in python? Regards