r - R 回溯断言中的正则表达式
问题描述
我正在尝试extract
使用tidyr
. 我已经在一个正则表达式练习站点中测试了我的正则表达式,该模式似乎有效,并且我使用的是lookbehind assertion
.
我有以下示例文本:
=[\"{ Key = source, Values = web,videoTag,assist }\",\"{ Key = type,
Values = attack }\",\"{ Key = team, Values = 2 }\",\"{ Key =
originalStartTimeMs, Values = 56496 }\",\"{ Key = linkId, Values =
1551292895649 }\",\"{ Key = playerJersey, Values = 8 }\",\"{ Key =
attackLocationStartX, Values = 3.9375 }\",\"{ Key =
attackLocationStartY, Values = 0.739376770538243 }\",\"{ Key =
attackLocationStartDeflected, Values = false }\",\"{ Key =
attackLocationEndX, Values = 1.7897727272727275 }\",\"{ Key =
attackLocationEndY, Values = -1.3002832861189795 }\",\"{ Key =
attackLocationEndDeflected, Values = false }\",\"{ Key = lastModified,
Values = web,videoTag,assist
我想获取后面的数字attackLocationX
(关于攻击位置的任何文本后面的所有数字。
但是,将以下代码与后向断言一起使用,我没有得到任何结果:
df %>%
extract(message, "x_start",'((?<=attackLocationStartX,/sValues/s=/s)[0-
9.]+)')
NA
如果未找到模式匹配,则此函数将返回,并且我的目标列是所有NA
值,尽管已在www.regexr.com
. 根据文档,R
模式匹配支持后向断言,所以我不确定这里还能做什么。
解决方案
我不确定后面的部分,但在 R 中,您需要转义反斜杠。如果您使用的是非 R 特定的正则表达式检查器,这并不明显。
更多信息在这里。
所以你可能希望你的正则表达式看起来像:
"attackLocationStartX,\\sValues\\s=\\s)[0-9.]+"
推荐阅读
- apache - 使用 docker-compose 和 dockerised apache2 在生产服务器中使用 SSL
- bash - 如何在特定字符串后从 IP:PORT 中提取端口?
- concatenation - 如何将多组列连接成几个新列?
- python - 异步下载例程中的错误处理
- python - edgecolors='None' 导致动画 3d 散点图错误
- python - 按自然顺序根据键对 OrderedDict 条目进行排序
- c# - OnCollisionEnter 不起作用:改变wheelcollider 的侧向摩擦刚度
- regex - Ansible替换或lineinfile?
- azure - 表的 Azure 存储帐户
- virtualhost - 我们可以在tomcat的server.xml文件中包含文件来配置虚拟主机吗