regex help please

Ken Corey ken at kencorey.com
Thu Feb 9 15:46:28 EST 2012


On 09/02/2012 20:24, Klaus on-rev wrote:
> in my current project I need to deal with VERY small XML files
> with maybe up to 20 entries.

Wait, didn't we just hear that you can't parse html (or XML) with 
regexps?  *grin*

> function mk_getXMLdata tText, tTag
>     get matchText(tText,"(?s)<"&  tTag&  ">(.*?)</"&  tTag&  ">",tValue)
>     return tValue
> end mk_getXMLdata

Throwing caution to the winds, this probably does something similar to 
what you want without further regexp voodoo:

function mk_replaceXMLdata tText, tTag, tNewText
    put tText into tValue
    if matchText(tText,"(?s)<"&  tTag&  ">(.*?)</"&  tTag&  ">",tValue) then
       put replaceText(tText, \
             "<"&tTag&">"&tValue&"</"&tTag&">",\
       "<"&tTag&">"&tNewText&"</"&tTag&">") into tValue
    end if
    return tValue
end mk_replaceXMLdata

And remember: zalgo is tony the pony! He's a comin!

-Ken




More information about the use-livecode mailing list