akitchin Posted July 21, 2006 Share Posted July 21, 2006 i'm trying to match an HTML tag that has no ending tag of the same type. my question is, how do i make it match any character/string that is NOT </tagname>? i'm currently using the character class [^</tagname>], but i'm thinking these days that it will match anything that isn't a <, a letter in the tagname, or a >. am i wrong? if so, how to i make sure it will match "anything that isn't </tagname>"?current regex:[code]$pattern = '@<'.$tagname.'[^<>]*?>[^</'.$tagname.'>]*?$@si'[/code]in addition, i guess my use of the ungreedy-modifying '?' in the second portion there is useless, since it will only match if it runs up to the end of the string (thus no amount of (un)greediness will change the matching nature)?[b]EDIT: solved it myself. needed to use a lookahead pattern, to make sure that it was matching the tag, any number of any character, that was NOT followed by the closing tag. current pattern:[/b][code]$pattern = '@<'.$tagname.'[^<>]*?>.*?(?!</'.$tagname.'>)$@si';[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.