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

2010-02-08 Thread Anthra Norell
Schif Schaf wrote: On Feb 7, 8:57 am, Tim Chase python.l...@tim.thechases.com wrote: Steve Holden wrote: Really? Under what circumstances does a simple one-for-one character replacement operation fail? Failure is only defined in the clarified context of what the OP wants :)

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

2010-02-07 Thread Shashwat Anand
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

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

2010-02-07 Thread @ Rocteur CC
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

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

2010-02-07 Thread Tim Chase
Schif Schaf wrote: On Feb 7, 12:19 am, Alf P. Steinbach al...@start.no wrote: I haven't used regexps in Python before, but what I did was (1) look in the documentation, [snip] code import re text = ( Lorem [ipsum] dolor sit amet, consectetur, adipisicing elit, sed do eiusmod

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

2010-02-07 Thread Steve Holden
@ Rocteur CC wrote: 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(']', '}')

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

2010-02-07 Thread Anssi Saari
Schif Schaf schifsc...@gmail.com writes: (brackets replaced by braces). I can do that with Perl pretty easily: for () { s/\[(.+?)\]/\{$1\}/g; print; } Just curious, but since this is just transpose, then why not simply tr/[]/{}/? I.e. why use a regular expression at all

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

2010-02-07 Thread Steve Holden
Tim Chase wrote: Schif Schaf wrote: On Feb 7, 12:19 am, Alf P. Steinbach al...@start.no wrote: I haven't used regexps in Python before, but what I did was (1) look in the documentation, [snip] code import re text = ( Lorem [ipsum] dolor sit amet, consectetur, adipisicing

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

2010-02-07 Thread Tim Chase
Steve Holden wrote: Tim Chase wrote: And to answer those who are reaching for other non-regex (whether string translations or .replace(), or pyparsing) solutions, it depends on what you want to happen in pathological cases like s = Dangling closing] with properly [[nested]] and

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

2010-02-07 Thread Schif Schaf
On Feb 7, 8:57 am, Tim Chase python.l...@tim.thechases.com wrote: Steve Holden wrote: Really? Under what circumstances does a simple one-for-one character replacement operation fail? Failure is only defined in the clarified context of what the OP wants :)  Replacement operations only fail

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

2010-02-06 Thread Schif Schaf
Hi, I've got some text that looks like this: Lorem [ipsum] dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna aliqua. and I want to make it look like this: Lorem {ipsum} dolor sit amet, consectetur adipisicing

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

2010-02-06 Thread Alf P. Steinbach
* Schif Schaf: Hi, I've got some text that looks like this: Lorem [ipsum] dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut [labore] et [dolore] magna aliqua. and I want to make it look like this: Lorem {ipsum} dolor sit amet, consectetur

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

2010-02-06 Thread Schif Schaf
On Feb 7, 12:19 am, Alf P. Steinbach al...@start.no wrote: I haven't used regexps in Python before, but what I did was (1) look in the documentation, Hm. I checked in the repl, running `import re; help(re)` and the docs on the `sub()` method didn't say anything about using back-refs in the

[Regex] Search and replace?

2008-11-13 Thread Gilles Ganault
Hello I need to iterate through a variable, and for each pattern that matches, replace this with something else. I read the chapter in www.amk.ca/python/howto/regex/, but the output is wrong: === #Extract two bits, and rewrite the HTML person = re.compile('tr onMouseOver=(?Pitem1.+?).+?a

Re: [Regex] Search and replace?

2008-11-13 Thread Sion Arrowsmith
Gilles Ganault [EMAIL PROTECTED] wrote: #Extract two bits, and rewrite the HTML person = re.compile('tr onMouseOver=(?Pitem1.+?).+?a onmouseover=Tip(?Pitem2.+?)nbsp;/td') output = person.sub('tr onMouseOver=\1tda onmouseover=Tip\2/td', input) Does someone have a simple example handy so I can