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


Groups > comp.lang.python > #35108

Re: Pattern-match & Replace - help required

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'framework.': 0.07; 'subject:help': 0.07; 'python': 0.09; 'matched': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'skip:r 50': 0.09; 'help?': 0.16; 'received:80.91.229.3': 0.16; 'received:dip.t-dialin.net': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-dialin.net': 0.16; 'subject:required': 0.16; 'string': 0.17; 'wrote:': 0.17; 'matching': 0.23; 'somebody': 0.23; "i've": 0.23; 'header:User-Agent:1': 0.26; 'replace': 0.27; 'header:X-Complaints-To:1': 0.28; "skip:' 20": 0.32; 'to:addr :python-list': 0.33; 'skip:d 20': 0.34; 'text.': 0.35; 'received:org': 0.36; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'subject:-': 0.40; 'header:Received:5': 0.40; 'help': 0.40; 'urgent': 0.66; 'subject: & ': 0.67
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Peter Otten <__peter__@web.de>
Subject Re: Pattern-match & Replace - help required
Date Wed, 19 Dec 2012 14:16:18 +0100
Organization None
References <e6346fb0-59a2-4e76-9bbf-6f04521e41cd@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding 7Bit
X-Gmane-NNTP-Posting-Host p50849047.dip.t-dialin.net
User-Agent KNode/4.7.3
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.1046.1355922991.29569.python-list@python.org> (permalink)
Lines 26
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1355922991 news.xs4all.nl 6947 [2001:888:2000:d::a6]:51646
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:35108

Show key headers only | View raw


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)

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


Thread

Pattern-match & Replace - help required AT <matifayaz@gmail.com> - 2012-12-19 02:42 -0800
  Re: Pattern-match & Replace - help required Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-19 10:51 +0000
    Re: Pattern-match & Replace - help required AT <matifayaz@gmail.com> - 2012-12-19 03:01 -0800
      Re: Pattern-match & Replace - help required Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-12-19 11:09 +0000
  Re: Pattern-match & Replace - help required Thomas Bach <thbach@students.uni-mainz.de> - 2012-12-19 12:27 +0100
    Re: Pattern-match & Replace - help required AT <matifayaz@gmail.com> - 2012-12-19 03:53 -0800
    Re: Pattern-match & Replace - help required AT <matifayaz@gmail.com> - 2012-12-19 03:53 -0800
  Re: Pattern-match & Replace - help required Peter Otten <__peter__@web.de> - 2012-12-19 14:16 +0100
    Re: Pattern-match & Replace - help required AT <matifayaz@gmail.com> - 2012-12-19 05:41 -0800
      Re: Pattern-match & Replace - help required Alexander Blinne <news@blinne.net> - 2012-12-19 15:11 +0100
        Re: Pattern-match & Replace - help required MRAB <python@mrabarnett.plus.com> - 2012-12-19 14:23 +0000
    Re: Pattern-match & Replace - help required AT <matifayaz@gmail.com> - 2012-12-19 05:41 -0800

csiph-web