Jump to content

negating entire string vs. class


akitchin

Recommended Posts

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]
Link to comment
https://forums.phpfreaks.com/topic/15221-negating-entire-string-vs-class/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.