写一个C#正则表达式替换内容
<scriptsrc="../../Jscript/jquery-1.6.4.min.js"language="javascript"type="text/javascr...
<script src="../../Jscript/jquery-1.6.4.min.js" language="javascript" type="text/javascript"></script>
<script src="../../Jscript/jquery.boxy.js" language="javascript" type="text/javascript"></script>
<script src="../../Jscript/jquery.pager.js" type="text/javascript"></script>
<script src="../../Jscript/jquery.tmpl.min.js" type="text/javascript"></script>
替换为
<script src="../../Jscript/jquery-1.6.4.min.js?ccc=ttt" language="javascript" type="text/javascript"></script>
<script src="../../Jscript/jquery.boxy.js?ccc=ttt" language="javascript" type="text/javascript"></script>
<script src="../../Jscript/jquery.pager.js?ccc=ttt" type="text/javascript"></script>
<script src="../../Jscript/jquery.tmpl.min.js?ccc=ttt" type="text/javascript"></script> 展开
<script src="../../Jscript/jquery.boxy.js" language="javascript" type="text/javascript"></script>
<script src="../../Jscript/jquery.pager.js" type="text/javascript"></script>
<script src="../../Jscript/jquery.tmpl.min.js" type="text/javascript"></script>
替换为
<script src="../../Jscript/jquery-1.6.4.min.js?ccc=ttt" language="javascript" type="text/javascript"></script>
<script src="../../Jscript/jquery.boxy.js?ccc=ttt" language="javascript" type="text/javascript"></script>
<script src="../../Jscript/jquery.pager.js?ccc=ttt" type="text/javascript"></script>
<script src="../../Jscript/jquery.tmpl.min.js?ccc=ttt" type="text/javascript"></script> 展开
3个回答
展开全部
MatchCollection titleMatch = Regex.Matches(htmlCode,@"<script.*?[^>]*?>",RegexOptions.Singleline | RegexOptions.IgnoreCase);
foreach(Match t in titleMatch )
{
string str_scriptold= t.Groups[0].Value;
string str_jsold=Regex.Match(t,@"<script[^>]*?src=""[^\""|\'].*?[\"",\']");
string str_js=str_jsold.substring(0,str_jsold.length-1);
str_js+="?tt="+datetime.now.tostring();
string str_script=str_scriptold.Replace(str_jsold,str_js);
htmlCode.Replace(str_scriptold,str_script);
}
foreach(Match t in titleMatch )
{
string str_scriptold= t.Groups[0].Value;
string str_jsold=Regex.Match(t,@"<script[^>]*?src=""[^\""|\'].*?[\"",\']");
string str_js=str_jsold.substring(0,str_jsold.length-1);
str_js+="?tt="+datetime.now.tostring();
string str_script=str_scriptold.Replace(str_jsold,str_js);
htmlCode.Replace(str_scriptold,str_script);
}
追问
编译不通报错了
追答
oo 不好意思 在后面加上.Groups[0].Value;
展开全部
string addCode = "?ccc=ttt";
Regex linkReg = new Regex("<script [^>]*src=\"([^\"]*)\"");
MatchCollection linkCollection = linkReg.Matches(richTextBox1.Text);
foreach (Match linkMatch in linkCollection)
{
richTextBox1.Text = richTextBox1.Text.Replace(linkMatch.Groups[1].Value.Trim(), linkMatch.Groups[1].Value.Trim() + addCode);
}
Regex linkReg = new Regex("<script [^>]*src=\"([^\"]*)\"");
MatchCollection linkCollection = linkReg.Matches(richTextBox1.Text);
foreach (Match linkMatch in linkCollection)
{
richTextBox1.Text = richTextBox1.Text.Replace(linkMatch.Groups[1].Value.Trim(), linkMatch.Groups[1].Value.Trim() + addCode);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
用正则表达式?
你要替换什么呢?
你要替换什么呢?
追问
要用C# 给每一个script 标签中的引用地址加上时间戳如何替换?
例如:
替换为:
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询