我想用空格替換所有出現的"/* anytext here */"
(其中anytext here
可能是不同類型的文本)。我試圖做的是用空格替換所有註釋。正則表達式爲/ * ... */
我創建了一個正則表達式:
Regex regex = new Regex(@"/\*.*\*/");
...但它沒有考慮多/* ... */
模式的存在。例如,這個字符串:
"she /*sells*/ sea shells /*by the*/ sea shore"
...變爲:
"she sea shore"
...而我要的是:
"she sea shells sea shore"
有人能以正確的正則表達式的幫助嗎?
任何理由'string.Split'和'string.Replace'不會做? – Oded 2012-08-07 20:03:49
在你的正則表達式中,因爲astrisk是一個特殊字符,所以你必須用一個反斜槓(或任何「\」)來轉義它。 – Matthew 2012-08-07 20:05:23
@Matthew,反斜槓一直存在,但沒有顯示,因爲OP沒有使用代碼格式。 – 2012-08-07 20:55:59