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


Groups > comp.lang.python > #35137

Re: Pattern-match & Replace - help required

Newsgroups comp.lang.python
Date 2012-12-19 05:41 -0800
References <e6346fb0-59a2-4e76-9bbf-6f04521e41cd@googlegroups.com> <mailman.1046.1355922991.29569.python-list@python.org>
Subject Re: Pattern-match & Replace - help required
From AT <matifayaz@gmail.com>
Message-ID <mailman.1060.1355935196.29569.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious 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