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
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
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
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",
>>>
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?
@ 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('[',
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
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
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
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
* 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
11 matches
Mail list logo