Page 1 of 1

Trouble with exclusion in regular expressions

Posted: Mon Sep 16, 2002 5:09 pm
by NRiethmann
I've been going through some tutorials on the subject of regular expressions, but I can't seem to find anything explaining what I'm trying to do.

For the purposes of a larger script I'm working on, I need to match all text that does not fall between certain HTML tags. I'd like to be able to set a variable equal to these excluded tags, i.e.

Code: Select all

$excluded_tags = '(pre|blockquote)'
so that other folks can customize it to their liking.

My problem is that I can't seem to figure out how to use regex to say "Match everything except what falls between these tags".

Any ideas? Thanks in advance.

Posted: Mon Sep 16, 2002 5:13 pm
by Takuma
http://www.phpbuilder.com/columns/dario19990616.php3I had the same trouble but solved it by looking at the article http://www.phpbuilder.com/columns/dario19990616.php3.

Ok here's the answer:-
[quote=PHPBUILDER]You can also list which characters you DON'T want -- just use a '^' as the first symbol in a bracket expression (i.e., "%[^a-zA-Z]%" matches a string with a character that is not a letter between two percent signs). [/quote]

Well if it isn't this quote just read through it because I found the answer there so it should be there.