﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>IT博客-不再回头 .net学习日记＆资料-随笔分类-正则表达式</title><link>http://www.cnitblog.com/sfep/category/2152.html</link><description>我再也不愿听你要求 我受够了你那些自私要求</description><language>zh-cn</language><lastBuildDate>Sat, 01 Oct 2011 15:27:41 GMT</lastBuildDate><pubDate>Sat, 01 Oct 2011 15:27:41 GMT</pubDate><ttl>60</ttl><item><title>清除网页源码里的 Script中的内容</title><link>http://www.cnitblog.com/sfep/archive/2006/03/18/7731.html</link><dc:creator>不再回头</dc:creator><author>不再回头</author><pubDate>Fri, 17 Mar 2006 23:32:00 GMT</pubDate><guid>http://www.cnitblog.com/sfep/archive/2006/03/18/7731.html</guid><wfw:comment>http://www.cnitblog.com/sfep/comments/7731.html</wfw:comment><comments>http://www.cnitblog.com/sfep/archive/2006/03/18/7731.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/sfep/comments/commentRss/7731.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/sfep/services/trackbacks/7731.html</trackback:ping><description><![CDATA[
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<span style="COLOR: #008080">1</span>
				<img src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">InputString</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> Regex.Replace(</span>
				<span style="COLOR: #0000ff">InputString</span>
				<span style="COLOR: #000000">, </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">(&lt;script[^&gt;]*?&gt;[\s\S]*?&lt;/script&gt;)</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">""</span>
				<span style="COLOR: #000000">, RegexOptions.IgnoreCase)</span>
		</div>清除网页源码里的 Script中的内容<br />其他的 差不多 可以同理了<img src ="http://www.cnitblog.com/sfep/aggbug/7731.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/sfep/" target="_blank">不再回头</a> 2006-03-18 07:32 <a href="http://www.cnitblog.com/sfep/archive/2006/03/18/7731.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>使用正则表达式求完整路径中的文件名 </title><link>http://www.cnitblog.com/sfep/archive/2006/03/17/7692.html</link><dc:creator>不再回头</dc:creator><author>不再回头</author><pubDate>Thu, 16 Mar 2006 16:39:00 GMT</pubDate><guid>http://www.cnitblog.com/sfep/archive/2006/03/17/7692.html</guid><wfw:comment>http://www.cnitblog.com/sfep/comments/7692.html</wfw:comment><comments>http://www.cnitblog.com/sfep/archive/2006/03/17/7692.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cnitblog.com/sfep/comments/commentRss/7692.html</wfw:commentRss><trackback:ping>http://www.cnitblog.com/sfep/services/trackbacks/7692.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp; 以前都是比较恶心的算法，找字符串中的最后一个"\"，再求出末尾的文件名。现在好啦，用.net中的正则表达式，可以非常漂亮的完成。&nbsp;&nbsp;<BR>&nbsp;&nbsp;<BR>
<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #008080">&nbsp;1</SPAN><IMG src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align=top><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">using</SPAN><SPAN style="COLOR: #000000">&nbsp;System.Text.RegularExpressions;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;2</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align=top><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;3</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #008000">//</SPAN><SPAN style="COLOR: #008000">用正则表达式求末尾文件&nbsp;</SPAN><SPAN style="COLOR: #008000"><BR></SPAN><SPAN style="COLOR: #008080">&nbsp;4</SPAN><SPAN style="COLOR: #008000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/None.gif" align=top></SPAN><SPAN style="COLOR: #000000">&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;GetFileName(</SPAN><SPAN style="COLOR: #0000ff">string</SPAN><SPAN style="COLOR: #000000">&nbsp;FullName)&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;5</SPAN><SPAN style="COLOR: #000000"><IMG id=Codehighlighter1_108_282_Open_Image onclick="this.style.display='none'; Codehighlighter1_108_282_Open_Text.style.display='none'; Codehighlighter1_108_282_Closed_Image.style.display='inline'; Codehighlighter1_108_282_Closed_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockStart.gif" align=top><IMG id=Codehighlighter1_108_282_Closed_Image style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_108_282_Closed_Text.style.display='none'; Codehighlighter1_108_282_Open_Image.style.display='inline'; Codehighlighter1_108_282_Open_Text.style.display='inline';" src="http://www.cnitblog.com/images/OutliningIndicators/ContractedBlock.gif" align=top>&nbsp;&nbsp;</SPAN><SPAN id=Codehighlighter1_108_282_Closed_Text style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff"><IMG src="http://www.cnitblog.com/images/dot.gif"></SPAN><SPAN id=Codehighlighter1_108_282_Open_Text><SPAN style="COLOR: #000000">{&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;6</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Regex&nbsp;re</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;Regex(</SPAN><SPAN style="COLOR: #000000">@"</SPAN><SPAN style="COLOR: #000000">\\[^\\]*$</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;7</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Match&nbsp;ma</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">re.Match(FullName);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;8</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">(&nbsp;ma.Success)&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">&nbsp;9</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;ma.Value.Substring(</SPAN><SPAN style="COLOR: #000000">1</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">10</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">else</SPAN><SPAN style="COLOR: #000000">&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">11</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/InBlock.gif" align=top>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</SPAN><SPAN style="COLOR: #0000ff">return</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #000000">""</SPAN><SPAN style="COLOR: #000000">;&nbsp;<BR></SPAN><SPAN style="COLOR: #008080">12</SPAN><SPAN style="COLOR: #000000"><IMG src="http://www.cnitblog.com/images/OutliningIndicators/ExpandedBlockEnd.gif" align=top>&nbsp;&nbsp;}</SPAN></SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN></DIV><BR>&nbsp; <BR>说明： <BR>&nbsp;&nbsp;&nbsp; 带转义字符串的匹配串前必须加@ <BR>&nbsp;&nbsp;&nbsp; [^\\]表示不能出现"\"集合 <BR>&nbsp;&nbsp;&nbsp; *表示前面的字符可以出现任意次&nbsp;&nbsp; 
<P>&nbsp;&nbsp;&nbsp; $表示匹配的字符串应该在行尾</P><img src ="http://www.cnitblog.com/sfep/aggbug/7692.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cnitblog.com/sfep/" target="_blank">不再回头</a> 2006-03-17 00:39 <a href="http://www.cnitblog.com/sfep/archive/2006/03/17/7692.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>