I have a HTML document with the a table which I want to replace, however I don’t know what the content of the table will be so I need to search for the opening and closing table tags and then replace the content between them. I’m a bit of a n00b with regular expressions so I’m having trouble working out how to do this… any ideas?
Update: The HTML in question is available to me as a string and I’m not able to insert any extra data or change the HTML in any way… I need to be able to search for a opening and closing pattern at the start and end of the table in the HTML and then replace the contents in-between. 🙂
Do NOT use regular expressons for this, look into parsers. For instance, load the HTML in a
DOMDocumentinstance, search the table with eitherDOMXPathorgetElementsByTagName, and use thereplaceNodeor other manipulation functions. Doing it with regexes is usually very unreliable.