I was going to suggest an offset variable, but as you say, it appears
that the subsequent regex search is on the just-updated text. I'm not
sure what the issue is (I have a dice rolling bot that uses regex and
inserts results after the relevant dice expression, and I use an
offset variable to adjust the insertion points by an amount equal to
the length of what was inserted on the previous iteration). Perhaps
there's a mutability issue with doc.getText()? I use Java, so I don't
know how that works.

Be interested to know the answer, though!

On Oct 14, 4:22 am, Chris Searle <[email protected]> wrote:
> Am having an issue that I don't understand.
> I have a bot that looks for URLs (regexp matching) and replaces them with an
> image.
>
> Here's a code piece:
>
> def OnBlipSubmitted(properties, context):
>   blip = context.GetBlipById(properties['blipId'])
>   doc = blip.GetDocument()
>
>   m = r.search(doc.GetText())
>
>   while m != None:
>     doc.DeleteRange(document.Range(m.start(0), m.end(0)))
>     image = getImage(m.group(2))
>     newimage = document.Image(image.thumb.source, caption=image.title,
> width=image.thumb.width, height=image.thumb.height)
>     doc.InsertElement(m.start(0), newimage)
>     m = r.search(doc.GetText())
>
> So - I grab the first match - remove it, insert an image then search again -
> on the new text.
>
> This works fine for the first URL - it gets it exactly right.
>
> However - if I add the following to a blip:
>
> http://www.example.com/foo/barbla blahttp://www.example.com/bar/foo
>
> I expect
>
> IMG bla bla IMG
>
> I get
>
> IMG bla bIMGfoo
>
> That is - the second one is three characters (always 3) too early both in
> start and end. From what I can see - its the values of m.start and m.end
> that are at fault. The actual match itself is correct - since the values of
> m.group(0) and m.group(2) are exactly right for the input. I'm uncertain as
> to why this is - what could be in the text that is confusing it. If anyone
> can give me any hints ?
>
> Oh - and while asking - what is the caption param of an Image for? It
> certainly doesn't appear in the blip even though it's being set.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Wave API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/google-wave-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to