regular expression in c#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jambalapamba
    New Member
    • Nov 2007
    • 23

    regular expression in c#

    hi all,

    i am trying to replace a string that is starting with http:// and ending with / for example


    type=hiddenvalu e=http://www.start.com/intl/default.aspx></FORM>href="http ://www.start.com/startservice/


    with

    type=hiddenvalu e=replace/intl/default.aspx></FORM>href="repl ace/startservice/

    Thank You
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Try:
    System.Text.Reg ularExpressions .Regex

    Take a look at:
    Now, next, and beyond: Tracking need-to-know trends at the intersection of business and technology

    Comment

    • jambalapamba
      New Member
      • Nov 2007
      • 23

      #3
      i tried the site but i am finding difficult to code the sequence for the Regex.Replace because i want to replace anything starting with http:// and ending / . i want replacing including http:// until the charcter / with something like project. can please can anyone give me sequence

      Comment

      • Plater
        Recognized Expert Expert
        • Apr 2007
        • 7872

        #4
        google it. Many people I'm sure have already done this

        Comment

        • jambalapamba
          New Member
          • Nov 2007
          • 23

          #5
          i searched hard but i could not get what i wanted i am new to regular expressions so if any one can help me with my qury it will be great

          Comment

          • balabaster
            Recognized Expert Contributor
            • Mar 2007
            • 798

            #6
            Originally posted by jambalapamba
            i searched hard but i could not get what i wanted i am new to regular expressions so if any one can help me with my qury it will be great
            What I would do is extract the whole string - punch it into a URI class and extract the host property.

            Regular expressions can be a pain in the ass to figure out if you don't really understand the syntax. I'm sure you can figure out the extraction of the whole string...anythi ng starting http to the end of the string (the first space if the string is formed properly with spaces replaced as %20. Create a new instance of the URI using.

            To do it in pure regular expressions though you've gotta do something like:

            "((http://){1})(\S(\.)?)+/)" Bear in mind that I didn't check this so I haven't thought about all the "what if's"...a for instance that won't take into account the fact that the last section in the address name can't have a "." in that string. But this and the cheat sheet I reference below will point you in the right direction. That string will verify that "http://myaddress.com./ is a valid address - which while I suppose technically it is, the last period is superfluous so you'll probably want to remove it.



            Also bear in mind that in C# you need to double up \ because C# reads it as an escape sequence and you actually need to include the char "\" in the string.

            Comment

            • jambalapamba
              New Member
              • Nov 2007
              • 23

              #7
              Thank you very much its not exactly working what i wanted but atleast i can tweak it around when i run the pattern you gave me this is what i got
              http://www.start.com/startservice/abcd hello ello yellow/ fdsadfassdf http://helo/
              was replaced by
              abcd hello ello yellow/ fdsadfassdf but i wanted it to be
              startservice/abcd hello ello yellow/ fdsadfassdf

              i will take it from here . Thank you very much for your help. I appreciate your time for me.

              Comment

              • jambalapamba
                New Member
                • Nov 2007
                • 23

                #8
                i found the answer "http://.*?/"

                Comment

                • StaticFix
                  New Member
                  • Nov 2007
                  • 1

                  #9
                  Check out regex tester tools .........to find the exact reg expression and use the replace method......... ...one such tool you can find in sourceforge site


                  http://code2dotnet.blo gspot.com

                  Comment

                  Working...