我试图拆分一个包含两个条目的字符串,每个条目都有特定的格式:
- 类别(如
active site
/region
),后面跟一个:
- 术语(如
His, Glu
/nucleotide-binding motif A
),后跟,
下面是我要拆分的字符串:
string <- "active site: His, Glu,region: nucleotide-binding motif A,"
这就是我迄今为止所try 的.除了两个空的子字符串外,它生成所需的输出.
unlist(str_extract_all(string, ".*?(?=,(?:\\w+|$))"))
[1] "active site: His, Glu" "" "region: nucleotide-binding motif A"
[4] ""
我如何go 掉空的子字符串?