get string from via Regex
-
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);
-
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);
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.
-
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);
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
-
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.
-
Thanks in advanced! How to do that in regex(Only cause the string has a lot of this href)...
Are you trying to parse an HTML document for its links? Then: no, do not use regex. There are libraries which can do that.