『壹』 如何正則表達式去掉代碼中的注釋
/*[sS]**/|//.*
將符合以上正則內容替換為空
『貳』 正則表達式過濾html標簽和標簽中的注釋
|using System;
// 不過仔細看,我這個也沒錯啊...
// MyRule=@"<(?:[^><]|版""[^""]""|'[^']')*>";
// 實際檢驗一下:權
using System.Text.RegularExpressions;
class Test
{
static void Main()
{
string s = @"<td onmouseover=""if (a > 0)"">abc</td>def";
string r = @"<(?:[^><]|""[^""]""|'[^']')*>";
string t = Regex.Replace(s, r, "");
Console.WriteLine(t); // 輸出:「 0)">abcdef」
}
}
『叄』 從文本中篩選內容 xml 正則表達式 c#
方法:移除掉「>」和"<"之間的字元
string newstring = Regex.Replace(「<a><b>zhege<c>haha</c></b></a>」, ">[^<]+<", "><");
『肆』 【C#】 如何刪除XML中的注釋
如果你只要得到<a name="1">This is a sample</a>作為字元串的話,可以用正則表達式。
先將XML轉化成字元串,
然後用正則表達式匹配
如果你最後還要得到XML文件,
則將其轉換成字元串後,用replace將<!--和-->替換成空,再轉換成xml再用C#的XML類來獲得<a>標簽的屬性及內容
『伍』 在線求助,如何利用正則表達式,過濾掉注釋代碼
java 不熟悉。 用 javascript 的話這樣 var sHtml = '如何用正則表達式' + '這里還有一些內容' + '' + '' + ''; sHtml = sHtml.replace(//gmi, ''); alert(sHtml); java似乎可以這樣: pattern = Pattern.compile(""); matcher = pattern.matche...
『陸』 批量去掉xml文件中的注釋最好方法
可以使用正則表達式去實現
『柒』 用正則表達式過濾 XML節點命名規范
<[^(xml|XML|\d|\.|\s)].*?>.*</[^(xml|XML|\d|\.|\s)].*?>
這里有的/要變成\/
<[^(xml|XML|\d|\.|\s)].*?>.*</[^(\1)].*?>
這個是只有一對標簽的匹配,不考慮多重標簽就可以簡寫
『捌』 求一正則表達式,或其他什麼辦法,把字元串中的注釋去掉
用Java正則表達式替換就行了.
完整的程序如下:
class tempt
{
public static void main(String[] args)
{
String s="<?xml version=\"1.0\" encoding=\"GB18030\"?><!--XML信息頭,必填--><UFTP><MsgHdrRq><RefId>10318</RefId><!--系統參考號--><TrnCode>1602</TrnCode><!--交易代碼-->";
System.out.println(s.replaceAll("\\<\\!\\-\\-.*?\\-\\-\\>", ""));
}
}
運行結果:
<?xml version="1.0" encoding="GB18030"?><UFTP><MsgHdrRq><RefId>10318</RefId><TrnCode>1602</TrnCode>
『玖』 求助一個c的去掉注釋的演算法!
用其他語言如perl對於某個目錄下的某一類型的文件中符合正則表達式的行清空
『拾』 正則表達式匹配xml文檔
stringstr="<ts_htmlEditor><STRONG><U><EM>asdasdasa<IMGsrc="~/Outside/GetFile.aspx?DP=%2FTextEditor%2FC64.gif"><SUB>aaaaaasdasd</SUB>asda</EM></U><FONTcolor=#00cc99size=5face="楷體">sdasdaww<IMGsrc="~/Outside/GetFile.aspx?DP=%2FTextEditor%2FBeforeHead_01.jpg"></FONT></STRONG></ts_htmlEditor>";
Regexreg=newRegex("(?i)<img[^>]*>");
stringstr2=reg.Replace(str,"");
Console.WriteLine(str2);