本文介绍了如何使用Regex提取asp标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好我想从文本中提取完整的aspx标签语法,以便它能给我标签的确切语法。 < asp:Label ID =lblrunat =serverText =Test>< / asp:Label> 我正在使用以下正则表达式 正则表达式reg =新正则表达式(@< asp:[az] + \ * ID =(?< ID> [^] *)\\s *文本=(小于?文本> [^] *)[^ /] * />中); 使用 (StreamReader sr = new StreamReader(路径)) // 其中path是我的网址 { while (sr.Peek()> ; = 0 ) { MessageBody = sr.ReadLine(); MessageBody = MessageBody.TrimStart(); 匹配m = reg.Match(MessageBody); } } 所以有人可以帮助我 按照回答张贴我试过但没用过 string MessageBody = String .Empty; string filePath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath; filePath = filePath + WebForm5.aspx; 使用(StreamReader sr = new StreamReader(filePath)) { while (sr.Peek()> = 0 ) { MessageBody = sr.ReadLine(); MessageBody = MessageBody.TrimStart(); string regexp = (?< openingtag>< ASP:?标签* GT)(<内容> *)(小于closingtag>)< / closingtag>< /内容>< / openingtag>中??? ; MatchCollection match = Regex.Matches(MessageBody,regexp); } } 解决方案 Hi all I want to extract the complete aspx label syntax from the text so that it should give me the exact syntax of a label.<asp:Label ID="lbl" runat="server" Text="Test"></asp:Label>I am using the following regexRegex reg = new Regex(@"<asp:[a-z]+\s*ID=(?<id>[^]*)\\s*Text=(?<text>[^]*)[^/]*/>");using (StreamReader sr = new StreamReader(path)) // where path is my url { while (sr.Peek() >= 0) { MessageBody = sr.ReadLine(); MessageBody = MessageBody.TrimStart(); Match m = reg.Match(MessageBody); } }So can some one help meAs per the answer posted I tried but didn't workedstring MessageBody = String.Empty; string filePath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath; filePath = filePath + "WebForm5.aspx"; using (StreamReader sr = new StreamReader(filePath)) { while (sr.Peek() >= 0) { MessageBody = sr.ReadLine(); MessageBody = MessageBody.TrimStart(); string regexp = "(?<openingtag><asp:label.*?>)(?<content>.*?)(?<closingtag>)</closingtag></content></openingtag>"; MatchCollection match = Regex.Matches(MessageBody, regexp); } } 解决方案 这篇关于如何使用Regex提取asp标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 18:42