• Home
  • Blog
  • Demos
  • About
  • ------------------
  • Articles
  • Csharp(59)
    • controls (4)
    • methods (5)
    • tutorials (50)
  • Html(1)
    • tutorials (1)
  • Java(10)
    • mobile (10)
  • Javascript(5)
    • tutorials (5)
  • Linux(3)
    • tutorial (3)
  • Math(10)
    • tutorials (10)
  • Php(15)
    • functions (1)
    • mysql (6)
    • tutorials (8)
  • Sql(23)
    • tutorials (23)
  • Vba(1)
    • tutorials (1)

Regexp replace IF NOT issue resolved :P

Written: 2009-12-21 15:14:45
Mood: Happy
Subject: programming
Just a short one here.
I was looking for a way to find all tags in a text (< and >) UNLESS they were PHP tags (<?php) or HTML comment tags (<!--).

The regexp for this was as follows:

$str = preg_replace('/\<(?!\\?)(?!\\!)(.*?)\>/', '', $str);


The key was that if you want multiple excludes (?()) then you just add them after each other. I was going mad trying to find a way to add them inside the same parenthesis.

Well, might be good to know :P