【发布时间】:2020-11-15 00:26:26
【问题描述】:
在字符串中,我试图提取0.4% 之后的12 month(s)\n$500
我搜索12 month(s)\n$500,然后获取后面的数字点号。
来自here,“要匹配文字“$”或“^”,您需要对它们、$ 和^ 进行转义。” 但是当我这样做时,我得到了错误:
Error: '\$' is an unrecognized escape in character string starting ""(?<=12 month(s)\\n\$"
我做错了什么?
x <- "Term Minimum investment Rate Interest type Get this GIC\n3 month(s)\n$500 0.15% Simple\nChoose this GIC\n6 month(s)\n$500 0.25% Simple\nChoose this GIC\n9 month(s)\n$500 0.30% Simple\nChoose this GIC\n12 month(s)\n$500 0.40% Simple\nChoose this GIC\n18 month(s)\n$500 0.50% Simple\nChoose this GIC\n18 month(s)\n$500 0.50% Compound\nChoose this GIC"
as.numeric(stringr::str_extract(x, "(?<=12 month(s)\\n\$500)\\d\\.\\d{1,}"))
【问题讨论】: