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. Extract the in-betweens...

Extract the in-betweens...

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

    Hey All! :-D I've been readin' up on Regular Expressions alot lately because I need to Extract words inbetween HTML tags for example I need to extract the words 'extract this!': Extract this! and also: Extract this URL I have followed many examples and read MSDN and I just can't get it to work. Can anyone please shed some light on this matter? Thanks in advance Jay. j.t.

    C 1 realJSOPR 3 Replies Last reply
    0
    • J jas0n23

      Hey All! :-D I've been readin' up on Regular Expressions alot lately because I need to Extract words inbetween HTML tags for example I need to extract the words 'extract this!': Extract this! and also: Extract this URL I have followed many examples and read MSDN and I just can't get it to work. Can anyone please shed some light on this matter? Thanks in advance Jay. j.t.

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Use regex grouping to match the bits you want to keep and build a new string, or to match the bits you want to remove, and then remove them.

      Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

      J 1 Reply Last reply
      0
      • C Christian Graus

        Use regex grouping to match the bits you want to keep and build a new string, or to match the bits you want to remove, and then remove them.

        Christian Graus Driven to the arms of OSX by Vista. "I am new to programming world. I have been learning c# for about past four weeks. I am quite acquainted with the fundamentals of c#. Now I have to work on a project which converts given flat files to XML using the XML serialization method" - SK64 ( but the forums have stuff like this posted every day )

        J Offline
        J Offline
        jas0n23
        wrote on last edited by
        #3

        Yay! Thanks lots Christian Graus.

        j.t.

        1 Reply Last reply
        0
        • J jas0n23

          Hey All! :-D I've been readin' up on Regular Expressions alot lately because I need to Extract words inbetween HTML tags for example I need to extract the words 'extract this!': Extract this! and also: Extract this URL I have followed many examples and read MSDN and I just can't get it to work. Can anyone please shed some light on this matter? Thanks in advance Jay. j.t.

          1 Offline
          1 Offline
          12Code
          wrote on last edited by
          #4

          jay_t55 wrote:

          need to extract the words 'extract this!': Extract this!

          Here you go..

                  string str = "<title>Extract this!</title>";
                  Regex RE = new Regex(@"(<title> )(\\w|\\S|\\s )+(</title> )");
                  MatchCollection MC = RE.Matches(str);
          
                  if (MC.Count == 0) MessageBox.Show("No match");
                  foreach (Match M in MC)
                  {                
                      string trimStr = "</title>";                
                      MessageBox.Show(M.ToString().Trim(trimStr.ToCharArray()));
                  }
          

          8.Kelvin()
          {
          while (!(the machine can program itself))
          Wont_stop_coding = true;
          }

          J 1 Reply Last reply
          0
          • 1 12Code

            jay_t55 wrote:

            need to extract the words 'extract this!': Extract this!

            Here you go..

                    string str = "<title>Extract this!</title>";
                    Regex RE = new Regex(@"(<title> )(\\w|\\S|\\s )+(</title> )");
                    MatchCollection MC = RE.Matches(str);
            
                    if (MC.Count == 0) MessageBox.Show("No match");
                    foreach (Match M in MC)
                    {                
                        string trimStr = "</title>";                
                        MessageBox.Show(M.ToString().Trim(trimStr.ToCharArray()));
                    }
            

            8.Kelvin()
            {
            while (!(the machine can program itself))
            Wont_stop_coding = true;
            }

            J Offline
            J Offline
            jas0n23
            wrote on last edited by
            #5

            Wow! Thank you so much 8Kelvin, very much appreciated!! :-D Jay.

            j.t.

            1 Reply Last reply
            0
            • J jas0n23

              Hey All! :-D I've been readin' up on Regular Expressions alot lately because I need to Extract words inbetween HTML tags for example I need to extract the words 'extract this!': Extract this! and also: Extract this URL I have followed many examples and read MSDN and I just can't get it to work. Can anyone please shed some light on this matter? Thanks in advance Jay. j.t.

              realJSOPR Offline
              realJSOPR Offline
              realJSOP
              wrote on last edited by
              #6

              What you want is an HTML parser (google is your friend). Don't mess around with regex because you'll spend a lot of time trying to figure it out. Believe me - downloading a parser will be much faster.

              "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
              -----
              "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

              P 1 Reply Last reply
              0
              • realJSOPR realJSOP

                What you want is an HTML parser (google is your friend). Don't mess around with regex because you'll spend a lot of time trying to figure it out. Believe me - downloading a parser will be much faster.

                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001

                P Offline
                P Offline
                PIEBALDconsult
                wrote on last edited by
                #7

                Hear hear! This is a wheel best not reinvented.

                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