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 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 fai

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

2010-02-07 Thread Schif Schaf
On Feb 7, 8:57 am, Tim Chase 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 if the OP's desired

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 c

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" wrote: >>> I haven't used regexps in Python before, but what I did was (1) look >>> in the >>> documentation, > [snip] >>> >>> import re >>> >>> text = ( >>> "Lorem [ipsum] dolor sit amet, consectetur", >>>

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

2010-02-07 Thread Anssi Saari
Schif Schaf 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 for this?

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('[',

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" wrote: I haven't used regexps in Python before, but what I did was (1) look in the documentation, [snip] import re text = ( "Lorem [ipsum] dolor sit amet, consectetur", "adipisicing elit, sed do eiusmod tempor", "incid

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

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 ei

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" 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 replacement

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

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 elit,

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('.+?)>.+?onmouseover="Tip(?P.+?) ') > >output = person.sub('' (note the backslash escaping). Oh, and don't use "input" as a name -- you're shadowing the builtin input function. -- \S -- [EMA

[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('.+?)>.+?', input) === Does som