Grep Challenge/Multi-line HTML chunks

Ken Ray kray at sonsothunder.com
Wed Apr 10 17:53:01 EDT 2002


Here you go (I'm assuming the string is in 'sourceString' and the
replacement text is in 'replaceString'):

on ReplaceFooter sourceString,replaceString
  local tStart,tEnd
  get matchChunk(tText,"(?s)<!--Footer Text-->(.*)</HTML>",tStart,tEnd)
  if it is true then
    put replaceString into char tStart to tEnd of sourceString
    return sourceString
  else
     answer "Matching error."
  end if
end ReplaceFooter

Keep in mind that this does not follow your rule "</HTML>" is on its own
line - it doesn't have to be. The regex (?s) tells MC to treat
'sourceString' as if everything was on one line, so line breaks are ignored.
If you want line breaks to be respected,  let me know and I'll give you
alternative code. But if this is for HTML, it shouldn't matter if </HTML> is
on its own line or not.

Enjoy!

Ken Ray
Sons of Thunder Software
Email: kray at sonsothunder.com
Web Site: http://www.sonsothunder.com/


----- Original Message -----
From: "Sivakatirswami" <katir at hindu.org>
To: <use-revolution at lists.runrev.com>
Sent: Wednesday, April 10, 2002 4:16 PM
Subject: Grep Challenge/Multi-line HTML chunks


> I am using Rev to build HTML pages and swop out code chunks of a large
> number of files. I could do this in BBEdit, but there is no custom tool
set
> in that environment... also I am untrained in grep...
>
> So: Challenge it this, I want to swap out the footer on 100's of HTML
pages
> unfortunately they were coded all by hand, passed through email, wrapped
to
> short lines (some) i.e. not consistent in line breaks.
>
> I need to grep for a string that starts with
>
> "<!--Footer Text-->"
>
> Following by quite a lot of HTML code on multiple lines and then
> ending with this on it's own line:
>
> "</HTML>"
>
> The grep has to escape the forward slashes, all the tagging characters,
> colons, exclamation marks, end lines (mac endlines) and all regular
numbers
> and characters in between... is this possible with the new grep in Rev and
> if so, can someone give me the grep string?
>
> Hinduism Today
>
> Sivakatirswami
> Editor's Assistant/Production Manager
> katir at hindu.org
> www.HinduismToday.com, www.HimalayanAcademy.com,
> www.Gurudeva.org, www.hindu.org
>
> Read The Master Course Lesson of the Day at
> http://www.gurudeva.org/lesson.shtml
>
> _______________________________________________
> use-revolution mailing list
> use-revolution at lists.runrev.com
> http://lists.runrev.com/mailman/listinfo/use-revolution
>




More information about the use-livecode mailing list