【发布时间】:2019-05-06 04:05:19
【问题描述】:
我已使用 Mac 的 Expressions 来确认我的 Regex 是否有效,但我找不到从我的文本文件中提取信息的命令。我有 2,500 个文本文件,我需要提取每个文档的日期以填充数据集。仅供参考,“日期”是要提取的第一个变量,还会有其他变量。文件的格式各不相同,并且有多个日期。我只对每个文件的第一个日期感兴趣。一些文件的日期换行,另一些文件以“日期”或“日期”开头。
每个文本文档的示例:
Bangor
dorset
LL56 43r
date: 10 july 2009
take notice: the blah blah blah text goes here and there's lots of it.
action:
有效的正则表达式:
"\\d{1,2}\\s+(?:january|february|march|april|may|june|july|august|september|october|november|december)\\s+\\d{4}"
文本文档在 R Studio 环境中作为单个元素字符向量可见。我想“按原样”提取文本,所以类似于...
> strapply(NoFN, ("\\d{1,2}\\.?:january|february|march|april|may|june|july|august|september|october|november|december\\.\\d{4}")[[1]]
> [1] 10 july 2009
显然这实际上不起作用!
非常感谢! 伊恩
【问题讨论】: