regex question in matchChunk function

Chris Sheffield cmsheffield at gmail.com
Tue Dec 15 13:46:01 EST 2009


I am not very familiar with regular expressions, and I'm wondering if someone more knowledgeable could give me a hint as to how to accomplish this.

Given a passage of text, I need to find every instance of certain words within that text and draw a box around them. The box drawing I can handle just fine by including "box" in the textStyle of the found chunk. But it's finding the instances that I'm struggling with. Here is my code. Big warning! This should not be run as is, if anyone wants to attempt it. The second repeat will go forever.

repeat for each line tWord in tDiffWords
        repeat until matchChunk(tStoryText, "(?i)\b(" & tWord & ")\b", tStartChar, tEndChar) is false
           
            put the textStyle of char tStartChar to tEndChar of fld "StoryText" into tStyle
            if tStyle is empty or tStyle is "plain" then
                put "box" into tStyle
            else
                put comma & "box" after tStyle
            end if
            set the textStyle of char tStartChar to tEndChar of fld "StoryText" to tStyle
           
        end repeat
    end repeat

What I need is some way to use the matchChunk function and continue the search where the last search ended. I read through some regex documentation and came across "\G", but this doesn't seem to work in Rev. But maybe I'm not putting it in the right place in my search string.

Can anyone help? Is there a way to do this? Or can someone recommend another method of accomplishing the same thing? Keep in mind that this needs to search whole words in a story passage, and we're dealing with all kinds of punctuation here, including hyphens, em dashes, etc.

Thanks,
Chris

--
Chris Sheffield
Read Naturally, Inc.
www.readnaturally.com




More information about the use-livecode mailing list