C# 正则表达式替换问题
--------------------编程问答--------------------
Match m1 = Regex.Match(this.richTextBox1.Text, "src=\".*jquery.*\"");
Match m2 = Regex.Match(this.richTextBox1.Text, "src=\".*knockout.*\"");
Match m3 = Regex.Match(this.richTextBox1.Text, "src=\".*priv.*\"");
if (m1.Success || m2.Success || m3.Success)
return;
Match m4 = Regex.Match(this.richTextBox1.Text, @"<script.*\.js");
MessageBox.Show(m4.Value);
MessageBox.Show(this.richTextBox1.Text.Replace(m4.Value, m4.Value + "tt==dd"));
拿去改改 --------------------编程问答--------------------
string s = @"<script src=""../../Jscript/jquer5-1.6.4.min.js"" language=""javascript"" type=""text/javascript""></script>";--------------------编程问答-------------------- Regex.Replace(input,@"(?is)(?<=\<script.*?\.js).*?(?=['""])","?dd="+new Random().Next()); --------------------编程问答--------------------
string r = Regex.Replace(s, @"(?is)(?<=<script src=([""']))(.*?)(?=\1)", delegate(Match match)
{
bool b = Regex.IsMatch(match.Groups[2].Value, @"(?i)jquery|knockout|priv");
if (!b)
return match.Groups[2].Value + "?tt=" + DateTime.Now.Ticks;
else
return match.Groups[2].Value;
});
输出r;
--------------------编程问答--------------------
string tempStr = File.ReadAllText(@"C:\Documents and Settings\Administrator\桌面\Test.txt", Encoding.GetEncoding("GB2312"));//读取tx
string pattern = @"(?i)(?<=<script[^>]*?src=(['""])((?!(jquery|knockout|priv)).)+\.js)";
tempStr = Regex.Replace(tempStr,pattern,"?tt==dd");
--------------------编程问答--------------------
string s = @"<script src=""../../Jscript/jquer5-1.6.4.min.js"" language=""javascript"" type=""text/javascript""></script>";
string pattern = @"(?i)(?<=<script[^>]*?src=(['""])((?!(jquery|knockout|priv)).)+\.js)(?=([^>]*?></script>))";
s= Regex.Replace(s,pattern,"?tt==dd");
大神就是大神,正则也是大神 --------------------编程问答--------------------
大哥你写得太好了,能不能给我解释一下呢?有点看不懂
补充:.NET技术 , C#