Grep -- How to match segment containing many lines
Klaus Major
klaus at major-k.de
Sat May 12 10:01:50 EDT 2007
Hi Swami,
> I want to replace a chunk many files
>
> <div id="linklist">
> # lots of other stuff here, many lines all inconsistent
> across many files##
> </html>
>
> <div id="linklist">(.*?)</html>
>
> <div id="linklist">(.*)</html>
>
> isn't working... I suspect because of the many lines
> issue and I am having trouble finding the answer to
> how to get grep to ignore line endings?
>
> I'm sure it's really simple, but even after looking thru
> BBEdit's grep help I can't find it.
Good ol' Ken Ray once posted a code snippet that even iI could
understand and
I use it now all the time for extracting values from XML like files:
function getXMLdata theData, what
get matchText(theData,"(?s)<" & what & ">(.*?)</" & what &
">",retValue)
return retValue
end getXMLdata
This does only wok with fixed TAG names like:
-> theData = <oneTag>this and that and again this and that</oneTag>
-> get getXMLData theDAta,"oneTag"
Will return: his and that and again this and that
Maybe you can adapt this to your needs?
Like getting the desired string this way and then replace it with
another string?
You could change it this way two support two different TAGs
function getXMLdata theData, TagOne,TagTwo
get matchText(theData,"(?s)<" & TagOne & ">(.*?)</" & TagTwo &
">",retValue)
return retValue
end getXMLdata
Not tested, just an idea...
> TIA
>
> Sivakatirswami
> www.himalayanacademy.com
Regards
Klaus Major
klaus at major-k.de
http://www.major-k.de
More information about the use-livecode
mailing list