使用Matcher.appendReplacement的注意事項

使用Matcher.appendReplacement(String str1, String str2)時要注意,最好這樣用:
       Matcher.appendReplacement(String str1, String str2.replaceAll("////", "////////").replaceAll("//$", "//////$"));

1replaceAll("////", "////////")是爲了把"/"符號加上,如果不進行這部處理,"/"符號就會被刪除!
2
replaceAll("//$", "//////$")是爲了把"$"符號轉義,因爲"$"後加數字是表示第幾組的意思!

發佈了30 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章