Help with regex search-and-replace (Perl to Python)

@ Rocteur CC macosx at rocteur.cc
Sun Feb 7 04:52:10 EST 2010


On 07 Feb 2010, at 10:03, Shashwat Anand wrote:

> Here is one simple solution :
> >>> intext = """Lorem [ipsum] dolor sit amet, consectetur  
> adipisicing elit, sed do eiusmod tempor  incididunt ut [labore] et  
> [dolore] magna aliqua."""
>
> >>> intext.replace('[', '{').replace(']', '}')
> 'Lorem {ipsum} dolor sit amet, consectetur adipisicing elit, sed do  
> eiusmod tempor  incididunt ut {labore} et {dolore} magna aliqua.'
>
> Some people, when confronted with a problem, think "I know, I’ll use  
> regular expressions." Now they have two problems. — Jamie Zawinski  
> in comp.lang.emacs.

That is because regular expressions are what we learned in programming  
the shell from sed to awk and ksh and zsh and of course Perl and we've  
read the two books by Jeffrey and much much more!!!

How do we rethink and relearn how we do things and should we ?

What is the solution ?

Jerry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100207/677af1d0/attachment.html>


More information about the Python-list mailing list