我想換成以下的多個實例:GSUB更換和重新排序串
--- \n\n ## Some Text
有了:
Some Text \n ======================== \n\n
我想不通正則表達式的正確組合,這樣做。
幫助!這讓我瘋狂!
獎勵:告訴我如何做到相反的方向!
我想換成以下的多個實例:GSUB更換和重新排序串
--- \n\n ## Some Text
有了:
Some Text \n ======================== \n\n
我想不通正則表達式的正確組合,這樣做。
幫助!這讓我瘋狂!
獎勵:告訴我如何做到相反的方向!
使用捕獲組:
> s <- "--- \n\n ## Some Text\n\n--- \n\n ## Another Text"
> gsub("---\\s*\n\n\\s*##\\s*(.+)", "\\1 \n ======== \n\n", s, perl=TRUE)
[1] "Some Text \n ======== \n\n\n\nAnother Text \n ======== \n\n"
您可以顯示「正則表達式的錯誤組合」你已經到目前爲止已經試過?你會考慮使用「r」以外的東西嗎? – Floris