Regular expressions in PHP/PERL

Miscellaneous Forums/General Discussion/Regular expressions in PHP/PERL

I was wondering if anyone here knew about regular expressions in PHP or PERL? I'm trying to parse some web content and dynamically replace keywords with specific styling, but must not replace keywords contained in HTML tags or content headings. This is what I have so far:

/(?!<.*?) MY_WORD (?![^<>]*?>)/


This achieves stopping the replacement of content within HTML tags, but I still need to stop the replacement of content between heading and link tags - e.g.:

<h1>My_Content</h1>


and

<a href='http://www.blitzbasic.com'>My_Content</a>


Many thanks in advance.

Not sure if it is helpful to you. But when I need to dynamicly change pages or sink things into a template page. I normally just make my own commented tag... like <!-- title -->The Title<!-- title --> and then load the page and split by that term.. I then get an array where each odd value is a title. and each even value is all the other stuff. I then do whatever with that part in the array and then reconstruct and save out. You can technically split by anything, but if you stick to your own commented tag syntax, you run into no issues. You can do remarkably complex things with this.

www.customcleaningcompany.com uses a system like this in conjuntion with another site to do just this. If you view the source on pages like the services page. you'll see commented tags that are read by php elsewhere to create the specifics of the page.

All I did was the php stuff for the editor system. not the html or implimenting the tags themselves or the sites they are used in.

Thanks for your feedback DampeS8N. I wish I had specific tags available to do searches in, which would have made the whole job a lot easier, but all I have is a set of content in which the replacements can't be made within elements such as links and headers, plus not within any HTML tags.

I've managed to sort the issue of not performing searches within HTML tags, but have not been able to find a way to express not to search between </a> - </a> and <h1> - </h1> etc.