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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. get string from via Regex

get string from via Regex

Scheduled Pinned Locked Moved C#
regexquestion
5 Posts 4 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
    jojoba20
    wrote on last edited by
    #1

    i wanna to get text : فروش_آپارتمان-تهران-اسلام شهر-OQA2ADEAMAAwADUA.aspx from string : string s=@"href=\"فروش_آپارتمان-تهران-اسلام شهر-OQA2ADEAMAAwADUA.aspx\"\u003e\r\n \u003c"; I have tried this but not use : string _conD="href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))"; MatchCollection _mat = Regex.Matches(s, _conD, RegexOptions.None);

    R RaviBeeR 2 Replies Last reply
    0
    • J jojoba20

      i wanna to get text : فروش_آپارتمان-تهران-اسلام شهر-OQA2ADEAMAAwADUA.aspx from string : string s=@"href=\"فروش_آپارتمان-تهران-اسلام شهر-OQA2ADEAMAAwADUA.aspx\"\u003e\r\n \u003c"; I have tried this but not use : string _conD="href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))"; MatchCollection _mat = Regex.Matches(s, _conD, RegexOptions.None);

      R Offline
      R Offline
      Rob Philpott
      wrote on last edited by
      #2

      Depending on the variance of the line you are extracting from, perhaps you could use a non-regex approach. Personally I would go down this route as RegEx syntax is tricky, but each to their own. In you example you could do something like:

      string x = s.Replace("href=\"", string.Empty); // to remove first bit
      x = x.Substring(0, x.IndexOf('\\'); // to remove last part

      .. or something like that, no visual studio to hand.

      Regards, Rob Philpott.

      J 1 Reply Last reply
      0
      • J jojoba20

        i wanna to get text : فروش_آپارتمان-تهران-اسلام شهر-OQA2ADEAMAAwADUA.aspx from string : string s=@"href=\"فروش_آپارتمان-تهران-اسلام شهر-OQA2ADEAMAAwADUA.aspx\"\u003e\r\n \u003c"; I have tried this but not use : string _conD="href\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))"; MatchCollection _mat = Regex.Matches(s, _conD, RegexOptions.None);

        RaviBeeR Offline
        RaviBeeR Offline
        RaviBee
        wrote on last edited by
        #3

        For another alternative to Regex for your case, see my StringParser[^] article. /ravi

        My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com

        1 Reply Last reply
        0
        • R Rob Philpott

          Depending on the variance of the line you are extracting from, perhaps you could use a non-regex approach. Personally I would go down this route as RegEx syntax is tricky, but each to their own. In you example you could do something like:

          string x = s.Replace("href=\"", string.Empty); // to remove first bit
          x = x.Substring(0, x.IndexOf('\\'); // to remove last part

          .. or something like that, no visual studio to hand.

          Regards, Rob Philpott.

          J Offline
          J Offline
          jojoba20
          wrote on last edited by
          #4

          Thanks in advanced! How to do that in regex(Only cause the string has a lot of this href)...

          B 1 Reply Last reply
          0
          • J jojoba20

            Thanks in advanced! How to do that in regex(Only cause the string has a lot of this href)...

            B Offline
            B Offline
            Bernhard Hiller
            wrote on last edited by
            #5

            Are you trying to parse an HTML document for its links? Then: no, do not use regex. There are libraries which can do that.

            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