regex question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GS

    #1

    regex question

    what is a good regex expression for remove html <img ....tag?
    I tried
    "<img [/:.a-z =0-9\""_;&]*\->", RegexOptions.Ig noreCase)
    but it is not quite working

    thank you for your time


  • Göran Andersson

    #2
    Re: regex question

    Why not simply "<img[^>]>"?

    GS wrote:
    what is a good regex expression for remove html <img ....tag?
    I tried
    "<img [/:.a-z =0-9\""_;&]*\->", RegexOptions.Ig noreCase)
    but it is not quite working
    >
    thank you for your time
    >
    >

    Comment

    • GS

      #3
      Re: regex question

      thanks for replying. However I found this worked better for me

      myregex = New Regex("<img .*?(>|(/>|(</img>))",
      RegexOptions.Ig noreCase Or
      RegexOptions.Ex plicitCapture)
      It does not gobble up other tags fooling the <img .....on the same line.
      it also supposed to take care of xml also

      Credit is due to Dave Sexton for helping arriving at the above expression

      "Göran Andersson" <guffa@guffa.co mwrote in message
      news:e5DKUuM5GH A.3840@TK2MSFTN GP06.phx.gbl...
      Why not simply "<img[^>]>"?
      >
      GS wrote:
      what is a good regex expression for remove html <img ....tag?
      I tried
      "<img [/:.a-z =0-9\""_;&]*\->", RegexOptions.Ig noreCase)
      but it is not quite working

      thank you for your time

      Comment

      • Göran Andersson

        #4
        Re: regex question

        There is never ever an ending tag for the img tag, and even if there
        were, your pattern doesn't handle that.

        GS wrote:
        thanks for replying. However I found this worked better for me
        >
        myregex = New Regex("<img .*?(>|(/>|(</img>))",
        RegexOptions.Ig noreCase Or
        RegexOptions.Ex plicitCapture)
        It does not gobble up other tags fooling the <img .....on the same line.
        it also supposed to take care of xml also
        >
        Credit is due to Dave Sexton for helping arriving at the above expression
        >
        "Göran Andersson" <guffa@guffa.co mwrote in message
        news:e5DKUuM5GH A.3840@TK2MSFTN GP06.phx.gbl...
        >Why not simply "<img[^>]>"?
        >>
        >GS wrote:
        >>what is a good regex expression for remove html <img ....tag?
        >>I tried
        >>"<img [/:.a-z =0-9\""_;&]*\->", RegexOptions.Ig noreCase)
        >>but it is not quite working
        >>>
        >>thank you for your time
        >>>
        >>>
        >
        >

        Comment

        • GS

          #5
          Re: regex question

          So far I have not seem ending tag for <img ..at least for html.

          although I think I have sees some comments of XML <img tags and <object tags
          both have ending tags of sorts

          I did made mistake in thr regex for the ending tag by leaving out one right
          paranthesis

          myregex = New Regex("<img .*?(>|(/>)|(</img>))",


          "Göran Andersson" <guffa@guffa.co mwrote in message
          news:OqhvAdX5GH A.1248@TK2MSFTN GP03.phx.gbl...
          There is never ever an ending tag for the img tag, and even if there
          were, your pattern doesn't handle that.
          >
          GS wrote:
          thanks for replying. However I found this worked better for me

          myregex = New Regex("<img .*?(>|(/>|(</img>))",
          RegexOptions.Ig noreCase Or
          RegexOptions.Ex plicitCapture)
          It does not gobble up other tags fooling the <img .....on the same
          line.
          it also supposed to take care of xml also

          Credit is due to Dave Sexton for helping arriving at the above
          expression

          "Göran Andersson" <guffa@guffa.co mwrote in message
          news:e5DKUuM5GH A.3840@TK2MSFTN GP06.phx.gbl...
          Why not simply "<img[^>]>"?
          >
          GS wrote:
          >what is a good regex expression for remove html <img ....tag?
          >I tried
          >"<img [/:.a-z =0-9\""_;&]*\->", RegexOptions.Ig noreCase)
          >but it is not quite working
          >>
          >thank you for your time
          >>
          >>

          Comment

          • Göran Andersson

            #6
            Re: regex question

            GS wrote:
            So far I have not seem ending tag for <img ..at least for html.
            >
            although I think I have sees some comments of XML <img tags and <object tags
            both have ending tags of sorts
            Yes, but XML is a completely different thing. There the tag name "img"
            has no special meaning at all.
            I did made mistake in thr regex for the ending tag by leaving out one right
            paranthesis
            >
            myregex = New Regex("<img .*?(>|(/>)|(</img>))",
            It still doesn't handle the ending tag, if there ever was one. As the
            starting tag ends with ">" that will be caught instead of the ending tag.
            >
            "Göran Andersson" <guffa@guffa.co mwrote in message
            news:OqhvAdX5GH A.1248@TK2MSFTN GP03.phx.gbl...
            >There is never ever an ending tag for the img tag, and even if there
            >were, your pattern doesn't handle that.
            >>
            >GS wrote:
            >>thanks for replying. However I found this worked better for me
            >>>
            >> myregex = New Regex("<img .*?(>|(/>|(</img>))",
            >>RegexOptions. IgnoreCase Or
            >>RegexOptions. ExplicitCapture )
            >>It does not gobble up other tags fooling the <img .....on the same
            line.
            >>it also supposed to take care of xml also
            >>>
            >>Credit is due to Dave Sexton for helping arriving at the above
            expression
            >>"Göran Andersson" <guffa@guffa.co mwrote in message
            >>news:e5DKUuM5 GHA.3840@TK2MSF TNGP06.phx.gbl. ..
            >>>Why not simply "<img[^>]>"?
            >>>>
            >>>GS wrote:
            >>>>what is a good regex expression for remove html <img ....tag?
            >>>>I tried
            >>>>"<img [/:.a-z =0-9\""_;&]*\->", RegexOptions.Ig noreCase)
            >>>>but it is not quite working
            >>>>>
            >>>>thank you for your time
            >>>>>
            >>>>>
            >>>
            >
            >

            Comment

            Working...