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. System.Text.RegularExpressions.Regex

System.Text.RegularExpressions.Regex

Scheduled Pinned Locked Moved C#
comregextutorialquestion
8 Posts 5 Posters 2 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
    mimimimilaw
    wrote on last edited by
    #1

    string = "www.abc.com?page=123&no=456"; if I want to cut the "page=123", how to do it? I would like to use System.Text.RegularExpressions.Regex. finally string = "www.abc.com?no=456"; THANKS:laugh:

    R M S 3 Replies Last reply
    0
    • M mimimimilaw

      string = "www.abc.com?page=123&no=456"; if I want to cut the "page=123", how to do it? I would like to use System.Text.RegularExpressions.Regex. finally string = "www.abc.com?no=456"; THANKS:laugh:

      R Offline
      R Offline
      Revathij
      wrote on last edited by
      #2

      Do u need Regular Expression for this Format?

      M 1 Reply Last reply
      0
      • R Revathij

        Do u need Regular Expression for this Format?

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

        any method, which can do the same thing, is OK.

        R 1 Reply Last reply
        0
        • M mimimimilaw

          string = "www.abc.com?page=123&no=456"; if I want to cut the "page=123", how to do it? I would like to use System.Text.RegularExpressions.Regex. finally string = "www.abc.com?no=456"; THANKS:laugh:

          M Offline
          M Offline
          Michael Sync
          wrote on last edited by
          #4

          mimimimilaw wrote:

          if I want to cut the "page=123", how to do it?

          string str = "www.abc.com?page=123&no=456"; str = str.Replace("page=123&",""); MessageBox.Show (str);

          Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

          L 1 Reply Last reply
          0
          • M mimimimilaw

            any method, which can do the same thing, is OK.

            R Offline
            R Offline
            Revathij
            wrote on last edited by
            #5

            Try Regular Expression in this link .... http://regexlib.com/RETester.aspx?regexp_id=235[^]

            1 Reply Last reply
            0
            • M Michael Sync

              mimimimilaw wrote:

              if I want to cut the "page=123", how to do it?

              string str = "www.abc.com?page=123&no=456"; str = str.Replace("page=123&",""); MessageBox.Show (str);

              Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

              L Offline
              L Offline
              Le centriste
              wrote on last edited by
              #6

              This works only if page is always 123, which is probably not the case. Try this instead:

              Regex.Replace("www.abc.com?page=123&no=456", @"(?<urlstart>.*\?)page=\d+&(?<urlend>.*)", @"${urlstart}${urlend}")

              ----- If atheism is a religion, then not collecting stamps is a hobby. -- Unknown God is the only being who, to rule, does not need to exist. -- Charles Baudelaire

              M 1 Reply Last reply
              0
              • M mimimimilaw

                string = "www.abc.com?page=123&no=456"; if I want to cut the "page=123", how to do it? I would like to use System.Text.RegularExpressions.Regex. finally string = "www.abc.com?no=456"; THANKS:laugh:

                S Offline
                S Offline
                Scott Dorman
                wrote on last edited by
                #7

                Try using the Uri class. You would probably want to do something like

                Uri builder = new Uri("www.abc.com?page=123&no=456");
                string[] parts = builder.Query.Split('&');
                string final = String.Format("{0}?{1}", builder.AbsolutePath, parts[2]);

                Scott.


                —In just two days, tomorrow will be yesterday. [Forum Guidelines] [Articles] [Blog]

                1 Reply Last reply
                0
                • L Le centriste

                  This works only if page is always 123, which is probably not the case. Try this instead:

                  Regex.Replace("www.abc.com?page=123&no=456", @"(?<urlstart>.*\?)page=\d+&(?<urlend>.*)", @"${urlstart}${urlend}")

                  ----- If atheism is a religion, then not collecting stamps is a hobby. -- Unknown God is the only being who, to rule, does not need to exist. -- Charles Baudelaire

                  M Offline
                  M Offline
                  Michael Sync
                  wrote on last edited by
                  #8

                  I know.. but he doesn't ask for it.. :) anyway, thanks for your code..

                  Thanks and Regards, Michael Sync ( Blog: http://michaelsync.net) If you want to thank me for my help, please vote my message by clicking one of numbers beside "Rate this message". Why vote? Plz Read it here. Thank you. :)

                  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