Msg#: 3962841 posted 12:26 am on Jul 31, 2009 (gmt 0)
Since my user name should really be "I Suck At Regex", I'm wondering what the regex for an ereg replace would be needed to catch a string that is not contained in any form of html tag, so basically not within < >.
e.g. It should find and replace John Doe in:
"John Doe was born on..."
but not find/replace when John Doe's in any tag for example:
<img src="/jd.jpg" alt="John Doe at Webmasterworld" />
Msg#: 3962841 posted 1:00 am on Jul 31, 2009 (gmt 0)
I'm sorry, but I think you missed my point. I'm looking for a regular expression (regex) pattern that will find instances of a search text in a string as long as that search text is not contained within <>.
Msg#: 3962841 posted 8:03 pm on Aug 4, 2009 (gmt 0)
If the goal is to end up with an updated HTML page, I'd be a bit more brute-force in my approach because I believe that strip_tags just leaves you with the page content and no simple way to restore the stripped tags once you've made your changes.
I'd start by extracting the content between the <body> tags, followed by replacing all HTML tags with sequentially-numbered markers, storing the tags along the way so they could be restored by replacing the markers. (You might have to special-case <style></style> and <script></script> sections to avoid altering them.) That would make global changes to the document content via regexp simple(r). And once that's done, you just restore the tags that you removed in the first pass, and re-insert the results back into the <body></body>.