導航:首頁 > 凈水問答 > 過濾注釋正則表達式

過濾注釋正則表達式

發布時間:2021-12-10 12:58:23

㈠ 在線求助,如何利用正則表達式,過濾掉注釋代碼

java 不熟悉。 用 javascript 的話這樣 var sHtml = '如何用正則表達式' + '這里還有一些內容' + '' + '' + ''; sHtml = sHtml.replace(//gmi, ''); alert(sHtml); java似乎可以這樣: pattern = Pattern.compile(""); matcher = pattern.matche...

㈡ 用正則表達式在java怎麼去匹配注釋 //的單行注釋 /*單行注釋*/ /* *多行注釋 */

先說結果:
我是測試出來了正則表達式,但是是針對三種注釋,寫了三種正則。
沒有實現單一的正則表達式,支持所有的注釋類型的。
代碼你可以參考參考:

//單行注釋
String commentsStr = "//this is single line comments";
Pattern singleLineCommentP = Pattern.compile("^//.*?$");
Matcher foundSingleLineComment = singleLineCommentP.matcher(commentsStr);
boolean foundSingle = foundSingleLineComment.matches();
System.out.println(foundSingleLineComment);
System.out.println(foundSingle);

/*單行注釋*/
String doubleStarCommentStr = "/* this is double star comments */";
Pattern doubleStarCommentP = Pattern.compile("^/\\*.*?\\*/$");
Matcher foundDoubleStarComment = doubleStarCommentP.matcher(doubleStarCommentStr);
boolean foundDouble = foundSingleLineComment.matches();
System.out.println(foundDoubleStarComment);
System.out.println(foundDouble);

/*
*多行注釋
*/

String multiLineComments = "/* \n" +
"* this is \n" +
"* multi line comment \n" +
"*/";
Pattern multiLineCommentP = Pattern.compile("^/\\*.*\\*/$", Pattern.DOTALL);
Matcher foundMultiLineComment = multiLineCommentP.matcher(multiLineComments);
boolean foundMulti = foundMultiLineComment.matches();
System.out.println(foundMultiLineComment);
System.out.println(foundMulti);

感興趣的話,可以去看看我總結的:
crifan 正則表達式學習心得

(此處不給貼地址,請用google搜標題,即可找到帖子地址)

㈢ java中 用正則表達式想去掉一個字元串中的注釋,怎麼弄

你在Java中要轉義某個字元需要用兩個轉義符才行.

應該這么寫

str=str.replaceAll("/\*.*\*/","");

System.out.println(str);

㈣ 正則表達式過濾中文

/^(^([\\u4E00-\\u9FA5]|[\\uFE30-\\uFFA0]))*$/

你是要這個吧? ^在正則表達式中,還有字元串開始的意思....

㈤ 設計正則表達式 要求匹配被注釋掉的行

$pattern="#^(s*//.*?)$#m";//php語言的正則,用多行模式,你沒說明語言,自己參考語法改一個

㈥ 如何用正則表達式 過濾 特定內容

正則表達式:^\d+(\.\d+)?$
你可以用這個正則表達式匹配輸入的字元,如果不匹配說明是非法的字母和字元.

㈦ 求一正則表達式,或其他什麼辦法,把字元串中的注釋去掉

用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>

㈧ 如何正則表達式去掉代碼中的注釋

/*[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」
}
}

㈩ 正則表達式注釋

當正則表達式過於復雜時,可以像普通的程序語言那樣為正則表達式添加註釋,以方便閱讀。當設定了「x」修正符後,字元組(即][]內的內容)之外的所有空白字元會被忽略,#號和換行符之間的內容會被視為注釋。多說無益,舉個例子:

$text = '[email protected]';
$reg = '{
\b
#把捕獲的地址保存到$1
(
\w[-.\w]* #username
@
[-\w]+(\.[-\w]+)*\.(com|e|info) #hostname
)
\b
}ix';
//$reg = '/\b(\w[-.\w]*@[-\w]+(\.[-\w]+)*\.(com|e|info))\b/ix';
$text = preg_replace($reg,'<a href="mailto:$1">$1</a>',$text);
var_mp($text);

運行一下,你會發現郵箱地址被替換成一個鏈接了。

閱讀全文

與過濾注釋正則表達式相關的資料

熱點內容
安吉爾a6ro膜外套 瀏覽:512
煤礦500人每天生活污水有多少 瀏覽:838
污水處理廠需要規章制度 瀏覽:303
超濾機和納慮機 瀏覽:737
什麼東西祛水壺里的水垢最好 瀏覽:140
用七牛回源網站被標惡意 瀏覽:754
吉林餐廳洗滌污水處理設備多少錢 瀏覽:391
弱酸廢水可以排放嗎 瀏覽:645
反滲透氧化還原電位高怎麼調整 瀏覽:821
高溫除垢機 瀏覽:48
污水處理公司發展 瀏覽:319
安裝污水處理設備有哪些質量要求 瀏覽:163
飲水機帶水壺還有水怎麼辦 瀏覽:833
gpan超濾膜有毒嗎 瀏覽:247
污水處理廠經營期限 瀏覽:621
小型加濕器怎麼除垢 瀏覽:231
深圳市楠業水處理環保有限公司 瀏覽:905
凈水器頭道濾芯是什麼 瀏覽:137
保定污水處理池的蓋板廠家有哪些 瀏覽:761
電器上樹脂怎麼分解 瀏覽:30