我想根据类型组合(例如摩擦音+爆破音、爆破音+摩擦音、爆破音+液体、 ETC。)。我创建了一个连接相应音素的向量:
plosives <- c("p", "b", "t", "d", "k", "g")
fricatives <- c("f", "v", "s", "z", "ʂ", "ʐ", "x")
首先编写这些向量的目的是在编写不同的正则表达式时速记并快速引用每个辅音类型。我想搜索这两种类型(FP、PF、PP、FF)中的所有两个辅音组合。如何使用这些向量作为模式参数在 R 中编写正则表达式?
我知道crossing (fricatives, plosives)
将所有组合作为字符串提供给我,但在以下位置使用它时出现错误:CC.all <- str_extract_all(ruphondict$IPA, crossing (fricatives, plosives), simplify = T)
最佳答案
形成正则表达式的基本 R 方法。
paste(
apply(expand.grid(plosives, fricatives), 1, paste0, collapse = ""),
collapse = "|"
)
请注意,这实际上是一句单行话。
paste(apply(expand.grid(plosives, fricatives), 1, paste0, collapse = ""),collapse = "|")
关于r - 我可以在 R 中使用向量作为正则表达式模式参数吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72716818/