Peter Otten <__peter__ web.de> writes:
>
> > How can I do this this concatenation correctly?
>
> I think sub() is more appropriate than finditer() for your problem, e. g.:
>
> >>> def process(match):
> ... return "_%s_" % match.group(1).title()
> ...
> >>> re.compile("(peter)", re.I).sub(p
As Peter Otten said, sub() is probably what you want. Try:
---
import re
def _ok(matchobject):
# more complicated stuff happens here
return 1
def _massage(word):
return "_" + word + "_"
def _massage_or_not(matchobj):
if not _ok(ma
Peter Bengtsson wrote:
> I've got a regular expression that finds certain words from a longer
> string.
>>From "Peter Bengtsson PETER, or PeTeR" it finds: 'Peter','PETER','PeTeR'.
> The problem is when there are more than one matches. The match.start() and
> match.end() are for the original strin
I've got a regular expression that finds certain words from a longer string.
>From "Peter Bengtsson PETER, or PeTeR" it finds: 'Peter','PETER','PeTeR'.
What I then want to do is something like this:
def _ok(matchobject):
# more complicated stuff happens here
return 1
def _massage(wor