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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.