【发布时间】:2018-07-04 09:01:03
【问题描述】:
从这样的数据框,
data_frame <- data.frame(com=c("chiffres au 31/12/2015","chiffre au 31/12/2008","chiffres au 31/12/08","xxx","abcd"))
我想提取模式为 "chiffres"+white_space+"au"+white_space+"dd/mm/yyyy" 的所有表达式
我已经尝试过这种模式,但它不起作用:
data_frame$date_plus_chiffre=str_extract(string=data_frame$com,
pattern="(chiffres)\s(au)\s([0-9]{2})(/)([0-9]{2})(/)([0-9]{4})")
如何在正则表达式中指定空格?
感谢您的帮助。
【问题讨论】:
-
?regex状态:[:blank:] Blank characters: space and tab, and possibly other locale-dependent characters such as non-breaking space. -
如果您特别想检测空格而不是其他空白字符,也可以使用
[:space:]。