4
我試圖在每個大寫字母后加小寫字母后加小寫字母。這裏是例子:在每個大寫字母后加小寫字母后加小寫字母
cases <- c("XrefAcctnoAcctID", "NewXref1AcctID", "NewXref2AcctID", "ClientNo")
我有這樣的:
[1] "XrefAcctnoAcctID" "NewXref1AcctID"
[3] "NewXref2AcctID" "ClientNo"
,我想有這樣的:
"xref_acctno_acct_id"
"new_xref1_acct_id"
"new_xref2_acct_id"
"client_no"
我能夠走這麼遠:
> tolower(gsub("([a-z])([A-Z])", "\\1_\\2", cases))
[1] "xref_acctno_acct_id" "new_xref1acct_id"
[3] "new_xref2acct_id" "client_no"
但是"new_xref1acct_id"
"new_xref2acct_id"
doe不反映我想要的。
只是改變'[AZ]'分離'[A-Z0-9]'在你的正則表達式匹配人均之前的小寫字母或數字湖或者改成'(。)([A-Z])'來匹配首都之前的任何東西。 – Gregor