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 problem [modified]

regex problem [modified]

Scheduled Pinned Locked Moved C#
regexcsharphelpquestion
4 Posts 3 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.
  • U Offline
    U Offline
    uglyeyes
    wrote on last edited by
    #1

    Hi, my regex works fine in a regextest tool its just only when i try to filter the content via c# it doesnt work. here is my code

    string fName = @"data.txt";//path to text file StreamReader testTxt = new StreamReader(fName); string allRead = testTxt.ReadToEnd();//Reads the whole text file to the end testTxt.Close(); //Closes the text file after it is fully read. string regMatch = @"(?<=\<div class=""middleadimggold""\>).*?(?=\</div\>)"; //string to search for inside of text file. It is case sensitive. if (Regex.IsMatch(allRead, regMatch))//If the match is found in allRead { Console.WriteLine("found\n"); } else { Console.WriteLine("not found\n"); }

    part of the content that should match

    <div class="middleadimggold">

    <a class="asdf" href="http://www.asdf">
    asdf</a>
    <p>
    asdf</p>
    <p>asdf</p><p>asdf</p>

    <p><span class="blue">asdf</span>
    <a class="de" href="http://www.4asdf"><span class="a">(See on map)</span></a></p>

    <p><span class="blue">asdf</span></p>

    <span class="xx">

    asdf
    </span>

    </div>

    please note the spacing in the content, not sure if it matters?

    modified on Thursday, January 14, 2010 10:06 PM

    U R 2 Replies Last reply
    0
    • U uglyeyes

      Hi, my regex works fine in a regextest tool its just only when i try to filter the content via c# it doesnt work. here is my code

      string fName = @"data.txt";//path to text file StreamReader testTxt = new StreamReader(fName); string allRead = testTxt.ReadToEnd();//Reads the whole text file to the end testTxt.Close(); //Closes the text file after it is fully read. string regMatch = @"(?<=\<div class=""middleadimggold""\>).*?(?=\</div\>)"; //string to search for inside of text file. It is case sensitive. if (Regex.IsMatch(allRead, regMatch))//If the match is found in allRead { Console.WriteLine("found\n"); } else { Console.WriteLine("not found\n"); }

      part of the content that should match

      <div class="middleadimggold">

      <a class="asdf" href="http://www.asdf">
      asdf</a>
      <p>
      asdf</p>
      <p>asdf</p><p>asdf</p>

      <p><span class="blue">asdf</span>
      <a class="de" href="http://www.4asdf"><span class="a">(See on map)</span></a></p>

      <p><span class="blue">asdf</span></p>

      <span class="xx">

      asdf
      </span>

      </div>

      please note the spacing in the content, not sure if it matters?

      modified on Thursday, January 14, 2010 10:06 PM

      U Offline
      U Offline
      uglyeyes
      wrote on last edited by
      #2

      ok this fixed the problem if (Regex.IsMatch(allRead, regMatch, RegexOptions.Singleline) singleline option that is. thanks for nothing

      OriginalGriffO 1 Reply Last reply
      0
      • U uglyeyes

        ok this fixed the problem if (Regex.IsMatch(allRead, regMatch, RegexOptions.Singleline) singleline option that is. thanks for nothing

        OriginalGriffO Offline
        OriginalGriffO Offline
        OriginalGriff
        wrote on last edited by
        #3

        Didn't I tell you that yesterday[^]?

        All those who believe in psycho kinesis, raise my hand.

        "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
        "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

        1 Reply Last reply
        0
        • U uglyeyes

          Hi, my regex works fine in a regextest tool its just only when i try to filter the content via c# it doesnt work. here is my code

          string fName = @"data.txt";//path to text file StreamReader testTxt = new StreamReader(fName); string allRead = testTxt.ReadToEnd();//Reads the whole text file to the end testTxt.Close(); //Closes the text file after it is fully read. string regMatch = @"(?<=\<div class=""middleadimggold""\>).*?(?=\</div\>)"; //string to search for inside of text file. It is case sensitive. if (Regex.IsMatch(allRead, regMatch))//If the match is found in allRead { Console.WriteLine("found\n"); } else { Console.WriteLine("not found\n"); }

          part of the content that should match

          <div class="middleadimggold">

          <a class="asdf" href="http://www.asdf">
          asdf</a>
          <p>
          asdf</p>
          <p>asdf</p><p>asdf</p>

          <p><span class="blue">asdf</span>
          <a class="de" href="http://www.4asdf"><span class="a">(See on map)</span></a></p>

          <p><span class="blue">asdf</span></p>

          <span class="xx">

          asdf
          </span>

          </div>

          please note the spacing in the content, not sure if it matters?

          modified on Thursday, January 14, 2010 10:06 PM

          R Offline
          R Offline
          Ravi Sant
          wrote on last edited by
          #4

          you have asked question by your-self and replied it back too again with answer already given by someone.

          ♫ 99 little bugs in the code, 99 bugs in the code We fix a bug, compile it again 101 little bugs in the code ♫

          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