【发布时间】:2016-03-11 18:13:07
【问题描述】:
我需要找到字符串“Count of”之后的数字。 “Count of”字符串和数字之间可能有空格或符号。我有一些适用于 www.regex101.com 但不适用于 stringr str_extract 函数的东西。
library(stringr)
shopping_list <- c("apples x4", "bag of flour", "bag of sugar", "milk x2", "monkey coconut 3oz count of 5", "monkey coconut count of 50", "chicken Count Of-10")
str_extract(shopping_list, "count of ([\\d]+)")
[1] NA NA NA NA "count of 5" "count of 50" NA
我想得到什么:
[1] NA NA NA NA "5" "50" "10"
【问题讨论】: