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. Regular expressions: Show matches [modified]

Regular expressions: Show matches [modified]

Scheduled Pinned Locked Moved C#
regexcsharpcomjsonhelp
5 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.
  • M Offline
    M Offline
    MyPiano
    wrote on last edited by
    #1

    Hello C# programmers, I currently dabble in programming with regular expressions. My problem is that I don't know, how I can extract a match if the programm finds one in a string. I already googled, but I couldn't found a site that could explain me how to manage it. I already tried Match and MatchCollection but it did not work. My previous source is following:

    string test = "gjhsdjfjhfsdfjhsdf\ntztrzrtz\n\"http://screenshots.filesnetwork.com/68/potd/t\_1215615627\_85.jpg\\"\\nggdgfdg56ggdg";

    string pattern = @"|.+\""http\://screenshots\.filesnetwork\.com/68/potd/t_[0-9]+_[0-9]+\.jpg\"".+|""";

    Regex re = new Regex(pattern,RegexOptions.Multiline);

    I am helpless with the rest, even though I know that it won't be that difficult. I'm looking forward to your answers. :) Best regards MyPiano

    modified on Sunday, August 3, 2008 8:52 AM

    N 1 Reply Last reply
    0
    • M MyPiano

      Hello C# programmers, I currently dabble in programming with regular expressions. My problem is that I don't know, how I can extract a match if the programm finds one in a string. I already googled, but I couldn't found a site that could explain me how to manage it. I already tried Match and MatchCollection but it did not work. My previous source is following:

      string test = "gjhsdjfjhfsdfjhsdf\ntztrzrtz\n\"http://screenshots.filesnetwork.com/68/potd/t\_1215615627\_85.jpg\\"\\nggdgfdg56ggdg";

      string pattern = @"|.+\""http\://screenshots\.filesnetwork\.com/68/potd/t_[0-9]+_[0-9]+\.jpg\"".+|""";

      Regex re = new Regex(pattern,RegexOptions.Multiline);

      I am helpless with the rest, even though I know that it won't be that difficult. I'm looking forward to your answers. :) Best regards MyPiano

      modified on Sunday, August 3, 2008 8:52 AM

      N Offline
      N Offline
      Nicholas Butler
      wrote on last edited by
      #2

      Your pattern is broken and you're confusing Multiline and Singleline. I suggest you play with Expresso[^] ( it's free )

      ---------------------------------- Be excellent to each other :)

      M 1 Reply Last reply
      0
      • N Nicholas Butler

        Your pattern is broken and you're confusing Multiline and Singleline. I suggest you play with Expresso[^] ( it's free )

        ---------------------------------- Be excellent to each other :)

        M Offline
        M Offline
        MyPiano
        wrote on last edited by
        #3

        Thanks for the answer. The tool is great, but it does not tell me, how I can extract the Matches. The new pattern:

        string pattern = ".+(\"http\\://screenshots\\.filesnetwork\\.com/68/potd/t_[0-9]+_[0-9]+\\.jpg\").+";

        By the way, the real string I am searching in looks so:

        ...

        src="http://screenshots.filesnetwork.com/68/potd/t\_1215615627\_85.jpg" alt="Knights of the Old Republic 2" width="160" height="120"

        ...

        EDIT: I made a little progress:

        Match m = re.Match(webSource);
        richTextBox1.Text = m.Value;

        I get an extract from the whole html document now, but it is still to big. All I want to extract is this part, which my pattern shell find:

        http://screenshots.filesnetwork.com/68/potd/t\_1215615627\_85.jpg

        EDIT II: I think I got it now. The mistake was the .+ at the start and at the end. If someone finds more mistakes or has tipps for me, I would be glad to read them. :) Best regards Joris

        G 1 Reply Last reply
        0
        • M MyPiano

          Thanks for the answer. The tool is great, but it does not tell me, how I can extract the Matches. The new pattern:

          string pattern = ".+(\"http\\://screenshots\\.filesnetwork\\.com/68/potd/t_[0-9]+_[0-9]+\\.jpg\").+";

          By the way, the real string I am searching in looks so:

          ...

          src="http://screenshots.filesnetwork.com/68/potd/t\_1215615627\_85.jpg" alt="Knights of the Old Republic 2" width="160" height="120"

          ...

          EDIT: I made a little progress:

          Match m = re.Match(webSource);
          richTextBox1.Text = m.Value;

          I get an extract from the whole html document now, but it is still to big. All I want to extract is this part, which my pattern shell find:

          http://screenshots.filesnetwork.com/68/potd/t\_1215615627\_85.jpg

          EDIT II: I think I got it now. The mistake was the .+ at the start and at the end. If someone finds more mistakes or has tipps for me, I would be glad to read them. :) Best regards Joris

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          The Value property of the Match object contains the entire string that was matched. The Groups collection contains the values from the groups that you specified in the pattern, in this case the group matching the url.

          Despite everything, the person most likely to be fooling you next is yourself.

          M 1 Reply Last reply
          0
          • G Guffa

            The Value property of the Match object contains the entire string that was matched. The Groups collection contains the values from the groups that you specified in the pattern, in this case the group matching the url.

            Despite everything, the person most likely to be fooling you next is yourself.

            M Offline
            M Offline
            MyPiano
            wrote on last edited by
            #5

            Okay, thank you very much. :)

            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