用到生成静态页,里面的标签匹配问题。假如有一个一个HTML模板里面有标签:[comp:link id=8] ,也有可能是[comp:name id=6]之类。现在如何用正则找出这个标签?找出之后,我要取其中的类型:也就是想知道是: link还是name,再就是取出 id=6 这个6.跪求高手。
解决方案 »
- 两个Page.ClientScript.RegisterStartupScript怎么只运行一个;如何用默认的打印机直接打印
- 各位高手,请教一个问题
- 请教高手这个控件的编译方法
- cs文件怎么都没了??救命啊!!
- insert into 语句的语法错误
- 高手们帮我看看啊。急啊。如何获取gridview模版列的值。
- 请问大侠:ASP.NET网站中如何实现个性化身份验证?
- 求助:为什么xml文件(链接xsl文件)在IE中打开后,文章不分段落了?
- css样式不起作用????江湖救急!!!
- 请教!更新问题
- 用studio2008编辑时可看见图片,在IE运行时不显示图片,请高手指点。
- 求教一个Membership提供程序配置问题
MatchCollection matches = Regex.Matches(s, @"(?is)\[comp:(?<type>[^: ]+)\s+id=(?<value>\d+)\]");
foreach (Match match in matches)
{
Response.Write(match.Groups["type"].Value + "<br/>");
Response.Write(match.Groups["value"].Value + "<br/><br/>");
}
link
8name
6
string s = @":[comp:link id=8] ,也有可能是[comp:name id=6]";
Match match = Regex.Match(s, @"(?is)\[comp:(?<type>[^: ]+)\s+id=(?<value>\d+)\]");
Response.Write(match.Groups["type"].Value + "<br/>");
Response.Write(match.Groups["value"].Value + "<br/><br/>");
<li><a href="[newslist:link]><span>[newslist:name]</span></a></li><li class="menu_line2"></li>
{/comp:newslist}你看一下标签也应该能明白意思,就是先要取出{comp:newslist 的type值,根据type值来决定 {comp:newslist 与 {/comp:newslist} 之间的内容,再取里面的[newslist 标签 后面的值,,,
我看正则就像看天书一样还望能帮忙,多多感谢!!!
<li><a href=""[newslist:link]""><span>[newslist:name]</span></a></li><li class=""menu_line2""></li>
{/comp:newslist}";
Match match = Regex.Match(s, @"(?is)(?<={comp:newslist\s+type=)[^=} ]+(?=})");
Response.Write(match.Value + "<br/>");
输出:all
{comp:newslist type=all}
<li><a href="[newslist:link]><span>[newslist:name]</span></a></li><li class="menu_line2"></li>
{/comp:newslist}这一段。也是在一段HTML模板中,也有可能有多个。你告诉我怎么取“{comp:newslist type=all} 与 {/comp:newslist}之间的内容吧。其中type=“这里不固定” 。也就是要得到 <li><a href="[newslist:link]><span>[newslist:name]</span></a></li><li class="menu_line2"></li> 这一段。我再结合你一楼的再解决。
多谢多谢啦!因白天事情多。只有抽空来看下。晚上回去再试。
<li><a href=""[newslist:link]""><span>[newslist:name]</span></a></li><li class=""menu_line2""></li>
{/comp:newslist}";
MatchCollection matches = Regex.Matches(s, @"(?is)(?<={comp:newslist\s+type=.+?}).+?(?={/comp:newslist})");
foreach (Match match in matches)
Response.Write(Server.HtmlEncode(match.Value) + "<br/>");
http://blog.csdn.net/keymo_
其中的“学习笔记11(正则表达式详解)”
只有真正懂得了个符号的表达意义,才能写出不同需求的表达式,总不能每次都来问吧,程序员要有求知欲
{comp:newslist type=all}
<li><a href=""[newslist:link]""><span>[newslist:name]</span></a></li><li class=""menu_line2""></li>
{/comp:newslist}
----
多谢啊,我是不是太笨了啊。。以后一定要补一下正则。
<li><a href=""[newslist:link]""><span>[newslist:name]</span></a></li><li class=""menu_line2""></li>
{/comp:newslist}";
MatchCollection matches = Regex.Matches(s, @"(?is){comp:newslist\s+type=.+?}(.+?){/comp:newslist}");
foreach (Match match in matches)
{
Response.Write(Server.HtmlEncode(match.Value) + "<br/>");
Response.Write(Server.HtmlEncode(match.Groups[1].Value+"<br/><br/>"));
}