r - R中的正则表达式将单词与杂乱语音数据中的语音注释进行匹配
问题描述
我有带有语音注释的相当混乱的语音数据,例如:
data <- c("hi Greg (1.57) dropped your €johnnies¿",
"[ARF ] what's prostitute?",
"°wanna (get in) the €dri::ve°",
"my €go::d I can't get out here",
"Sco:::[ :tt↑ ]",
"↑where have you bee:::n",
"j's (.) lie there ((inhales sharply)) breathe",
"well↓ i can't feel [ any? ]")
我想提取那些包含某些音标的单词标记,特别是“€”、“°”、“↑”、“↓”、“:”和具有多个大写字母的标记。提取的“语法”是这样,但模式对我来说太复杂了,因为音标可以出现在单词之前、单词内部和单词之后。
pattern <- ""
extract <- function(x) unlist(regmatches(x, gregexpr(pattern, x, perl = T)))
result <- extract(data)
预期的结果是这样的:
> result
[1] "€johnnies¿" "ARF" "°wanna" "€dri::ve°" "€go::d" "Sco::::tt↑" "↑where" "bee:::n" "well↓" "feel↑"
有任何想法吗?
解决方案
您可能会考虑在问题的第一部分使用类似的东西,尽管您可以首先进行预处理以删除 [ ] 中的空格,就像在这种情况下Sco:::[ :tt↑ ]
[\s"]([€°↑↓:\w]*[€°↑↓:]+[€°↑↓:\w¿]*)[\s"]
https://regex101.com/r/nQVddI/2
编辑:
对于匹配超过 2 个大写字母的使用([A-Z]{2,})
,我看不到混合字母的示例,比如AsDfG
它也应该匹配吗?
推荐阅读
- java - 如何在基于 Apache ANT 的项目中设置特定 jar 文件的范围?
- cypress - 将别名与 cypressIO 一起使用时出现错误消息
- python - 比较Python中的数据框日期时间列值?
- macos - 在特定文件类型中搜索关键字
- javascript - 所有圆形元素相互卡住
- javascript - While 循环 - JavaScript
- html - 如何向 PayPal 按钮添加更多信息?
- python - 基于另一个文件中的共享字段,从一个文件中绘制多个序列
- spring - spring boot ant matchers 参数
- sql - 插入的数据未保存 Qt