Skip to main content
March 27, 2008
Answered

ReReplace all html tags except selected

  • March 27, 2008
  • 2 replies
  • 353 views
Folks,
I'm trying to figure out how to eliminate all html tags in a string except for <img> and <a> tags. Any ideas? I've been stumped for several days.
thanks,
/r
    This topic has been closed for replies.
    Correct answer
    Answer from the Regex Advise Forums at this link: http://regexadvice.com/forums/AddPost.aspx?PostID=40752

    ======================
    In it's simplest form I would suggest that might be:

    <(?!(?:a|img)\s|/a>)[^>]*>

    if CF doesn't like (?:):

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

    2 replies

    March 28, 2008
    Hi Azadi. Thanks for the idea, but it doesn't seem to work.

    None of the html tags get removed now.

    Any other ideas?
    Correct answer
    March 28, 2008
    Answer from the Regex Advise Forums at this link: http://regexadvice.com/forums/AddPost.aspx?PostID=40752

    ======================
    In it's simplest form I would suggest that might be:

    <(?!(?:a|img)\s|/a>)[^>]*>

    if CF doesn't like (?:):

    <(?!(a|img)\s|/a>)[^>]*>
    Inspiring
    March 28, 2008
    try this:

    rereplace(str, "<[^(\/?(a |img )][^>]*>", "", "ALL")

    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/