Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Regex to fix img tags

Regex to fix img tags

Scheduled Pinned Locked Moved C#
regexhtmlhelpquestion
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stephen Adam
    wrote on last edited by
    #1

    Hi there, I'm writing an XHTML site and i'm using FreeTextBox to do it, unfortunately is has a nasty habbit of breaking XHTML rules with upper case tags and removing closing slashes from image tags. Now i've written a function which fixes allot of HTML errors which it (or the user) may create. The functionalitu i'm missing is a regex which will turn foo into foo Can anyone supply a regex replace pattern which will do this? This is my function so far in case anyone else finds it useful. public static string MakeHTMLValid(string strInput) { strInput = Regex.Replace(strInput, "

    ", "

    "); strInput = Regex.Replace(strInput, "

    ", "

    "); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "

    ", "

    "); strInput = Regex.Replace(strInput, "

    ", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "

    ", "

    "); strInput = Regex.Replace(strInput, "

    ", "

    "); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
    ", "
    "); strInput = Regex.Replace(strInput, "
    ", "
    "); strInput = Regex.Replace(strInput, "
    ", "
    "); strInput = Regex.Replace(strInput, "
    ", "
    "); strInput = Regex.Replace(strInput, "class=normalText", "class=\"normalText\"", RegexOptions.IgnoreCase); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "


    ", "


    ",RegexOptions.IgnoreCase);

    L 1 Reply Last reply
    0
    • S Stephen Adam

      Hi there, I'm writing an XHTML site and i'm using FreeTextBox to do it, unfortunately is has a nasty habbit of breaking XHTML rules with upper case tags and removing closing slashes from image tags. Now i've written a function which fixes allot of HTML errors which it (or the user) may create. The functionalitu i'm missing is a regex which will turn foo into foo Can anyone supply a regex replace pattern which will do this? This is my function so far in case anyone else finds it useful. public static string MakeHTMLValid(string strInput) { strInput = Regex.Replace(strInput, "

      ", "

      "); strInput = Regex.Replace(strInput, "

      ", "

      "); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "

      ", "

      "); strInput = Regex.Replace(strInput, "

      ", ""); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "

      ", "

      "); strInput = Regex.Replace(strInput, "

      ", "

      "); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "
      ", "
      "); strInput = Regex.Replace(strInput, "
      ", "
      "); strInput = Regex.Replace(strInput, "
      ", "
      "); strInput = Regex.Replace(strInput, "
      ", "
      "); strInput = Regex.Replace(strInput, "class=normalText", "class=\"normalText\"", RegexOptions.IgnoreCase); strInput = Regex.Replace(strInput, "", ""); strInput = Regex.Replace(strInput, "


      ", "


      ",RegexOptions.IgnoreCase);

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Parsing nested tags with regular expressions is not a trivial task, but for the tag it should work fine: string to find: <img(?<content>[^>]+)> string to replace: <img${content} /> regards

      S 1 Reply Last reply
      0
      • L Lost User

        Parsing nested tags with regular expressions is not a trivial task, but for the tag it should work fine: string to find: <img(?<content>[^>]+)> string to replace: <img${content} /> regards

        S Offline
        S Offline
        Stephen Adam
        wrote on last edited by
        #3

        Thanks for that it worked like a charm :)

        "Gödel proved that any formal system that defines the primitive recursive functions must be either incomplete or inconsistent. In particular one could not prove from within the system that the system itself was consistent even though the question could be formulated within the system."

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups