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 :)
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
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
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
@ 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(']',
'}')
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
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
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
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
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
* 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
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
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
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
14 matches
Mail list logo