Trouble with exclusion in regular expressions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NRiethmann
Forum Newbie
Posts: 2
Joined: Fri Sep 13, 2002 3:40 pm

Trouble with exclusion in regular expressions

Post 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.
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post 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.
Post Reply