Based on your comment:
When they get imported into the system their paths for images, external css and scripts no longer work so I need to replace them with the actual path.
You might want to approach this differently, in my view. Let me explain/justify...
Template files uploaded by users should never be fully formed HTML files, otherwise it's not a "template" file. Templates should always be formatted to include meta data in the form of tags specific to that CMS. Document all the tags and their translations in the page where they upload the template so users know what format your CMS expects.
Then, handle exceptions by validating their uploaded template which means stripping anytags intended for or used by your global template(s) and leaving the rest.
The point is YOU control the organization of all these templates, how parsing is done in which ones, all of which when combined in the proper sequence render the final page. This is not the same as a user uploading 100% of the HTML and you having to account for a million variations and possibilities not only in syntax but in positioning and location of tags sometimes which can reference URL's and not just local paths. You cannot possibly account for all these things.
Nobody said this was easy, but this is the proper approach in a commercial application. In a home made, DIY "I don't care" site with a few users you can trust to follow the specifications and create well formed HTML all the time, obviously this approach isn't necessary.
And finally, what you actually asked for:
I'm putting this at the end as I want you to really slow down and read the advice I just gave, it's a wise approach when CMS's are involved. Parsing tags and their attributes is best done with regular expressions, just as you asked about. Here is an example:
//$html is the HTML source of an uploaded user template
//$new_header is a global template you setup with head and meta/title tags
That takes the source of an uploaded template, gets the contents of the title tag into $matches array and parses it into a global template. The last line removes the title tag entirely as a demonstration of how to strip tags beyond PHP's strip_tags() built in method. I know the example is redundant, but it's just to demo the technique of parsing meta data using regular expressions.
It's up to you to design a sensible template system, but in a nutshell, this is how it's usually done on most CMS's where users play an active role in adding content in the form of HTML. So you have full control.
Sorry for the long post, but wanted to fully explain the concepts here.