#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2011
    Posts
    1
    Rep Power
    0

    How to match a string which is not in the list?


    I use the following to match a html tag, 'img' or 'a',

    "/(<)([\/]?)([img|a][^>]*)(>)/"


    [img|a] gives the string either 'img' or 'a'.


    But, how to match a tag which is NOT either 'img' or 'a'?

    Thanks.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,295
    Rep Power
    9400
    No, actually, your regex matches any HTML tag that begins with an A, G, I, or M. Such as <a> and <i> and <img> and <map> and <meta>...
    Code:
    /<\/?(?!a|img)[^>]*>/

IMN logo majestic logo threadwatch logo seochat tools logo