所以,如果我想抓住不含評論系統之間的文本:獲取常規註釋語法之間的文本
/*this is a comment*/
//this is too
//and so is this...
This, however, isn't.
輸出將
This, however, isn't.
我怎麼能做到這一點的JavaScript?我要去搶它的正則表達式,但我不知道如何處理以空白結尾的註釋...
任何幫助,將不勝感激。
編輯:也許我一直不清楚。我有一個上述文本的數組。我想擺脫任何不在評論中的東西,我想按原樣顯示評論。所以:
/*This is a longggg
comment that crosses several lines
etc etc etc*/
this is plain text. i want to ignore this //however, this is another comment
/*one more comment here*/
這將被輸出爲:
/*This is a longggg
comment that crosses several lines
etc etc etc*/
//however, this is another comment
/*one more comment here*/
評論不會被任何腳本或編程語言讀取,它們在代碼運行時會被忽略。所以你根本看不懂評論。 –
@AbdulJabbarWebBestow - 我想他只是想使用JavaScript作爲解析器,給出了評論作爲一個字符串。 –
你究竟想要完成什麼? – charlietfl