Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Special Parsing HTML by C#

Last post 03-29-2008, 11:20 AM by caglar ak. 2 replies.
Sort Posts: Previous Next
  •  03-28-2008, 8:57 PM 40804

    Special Parsing HTML by C#

    Hi everyone

      <span class="FiyatSmallBlackBack"><b>Bizde:</b></span><span class="FiyatSmallBlue"><b> 26,00 USD + KDV</b></span> <br />

     In that HTML I want to parse 26,00 USD +KDV using c# but that html could be as that ; (no +KDV just 26,00 USD</b>)

    span class="FiyatSmallBlackBack"><b>Bizde:</b></span><span class="FiyatSmallBlue"><b> 26,00 USD </b></span> <br />

    I am using  >(?<fiyat1>.*?) USD+(?<KDV>.*?)<. Result of that regex is ><b>Bizde:</b></span><span class="FiyatSmallBlue"><b> 26,00 USD + KDV<

    But I want Just the 26,00 USD and if it is written +KDV thanks..

     

     

  •  03-29-2008, 12:37 AM 40808 in reply to 40804

    Re: Special Parsing HTML by C#

    If all you want is the text that is not within a tag, then the HTML DOM may be a better approach. This is also true if all you want is the text within <span></span> tags, of even if there are special attributes the span tag must have.

    However, this:

    (?<!<[^<>]*)\s*([0-9.,]+)\s*usd\s*(\+\s*kdv)?\s*(?![^<>]*>)

    with the 'ignore case' option set will find a string of digits (plus commas and decimal points) followed by the letters USD and optionally followed by a plus sign and the letters KDV as long as it is not inside a tag. I have allowed for spaces in various places which you may be able to cut out if you know they will never occur. The numeric amount will be in match group #1 and the "+KDV" will be in match group #2 if it is present in the text.

    Whether this will work depends on what else is in the text file that you are examining.

    Susan

     

  •  03-29-2008, 11:20 AM 40814 in reply to 40808

    Re: Special Parsing HTML by C#

    thanks susan your regex is enough..

View as RSS news feed in XML