Ok, that makes it a lot less straightforward..
Have a look at http://www.htdig.org/index.html, which popped up from a quick search on this forum. people seem to be happy about it.
If you want to write it from scratch, I am not sure, but I think you are setting yourself up for a lot of work (e.g., the need to create an index of your site in a database or flat file, or write a routine which opens each file during a search, and reg_exp() the pages.)
Please.. If I am completely off, and there is an easy way to do it.. Do correct me please!
J.