【发布时间】:2015-07-12 23:05:02
【问题描述】:
我正在尝试匹配以下有序和无序列表并提取项目符号/列表点。
library(stringr)
examples <- c(
"* Bullet 1\n* Bullet 2\n* Bullet 3",
"1. Bullet 1\n2. Bullet 2\n3. Bullet 3",
"* This is a test 1\n* This is a test with some *formatting*\n* This is a test with different _formatting_"
)
我想做的是:
- 以编程方式识别它是一个列表
- 仅将每个解析为列表项的文本
结果是
some_str_fun(example,pattern) # or multiples
"Bullet 1" "Bullet 2" "Bullet 3"
"Bullet 1" "Bullet 2" "Bullet 3"
"This is a test 1" "This is a test with some *formatting*"
"This is a test with different _formatting_"
我一直在使用以下模式和 str_extract/match,但似乎找不到完全实用的东西
[*]+\\s(.*?)[\n]* # for * Bullet X\n
[1-9]+[.]\\s(.*?)[\n]* # for 1. Bullet X\n
我在这些模式上尝试了很多不同的迭代,但似乎无法完全得到我想要的。
【问题讨论】:
-
是否可以有一个“0”:例如
10. Bullet? -
@Frank 不,我不这么认为。