首先,我想刪除文本中每行的空格。 我現在使用的正則表達式起作用,但它也刪除了應保留的空白行。刪除多行空格
我的正則表達式:
(?m)\s+$
我做了負回顧後的測試,但它不工作。
(?m)(?<!^)\s+$
樣品文字:
This text is styled with some of the text formatting properties.**
**The heading uses the text-align, text-transform, and color*
properties. The paragraph is indented, aligned, and the space*
***************************************************************
*between characters is specified. The underline is removed from*
this colored "Try it Yourself" link.*
***************************************************************
正如我所說的,它應該只刪除開頭和結尾的空格,但不是空行。
說明:(*) - 表示空格。
爲什麼不直接使用String.trim(如果要排除空行if語句添加)? –
由於修剪刪除空白行。 – developer033
我可以知道downvote的原因嗎? – developer033