我想使用
我有以下示例文本:
tidyr
中的extract
函数进行一些模式匹配。在正则表达式练习网站上测试了我的正则表达式,该模式似乎有效,并且我正在使用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
,尽管在www.regexr.com
上测试了该模式,但我的目标列仍然是所有NA
值。根据文档,R
模式匹配支持向后断言,因此在这里我不确定还能做什么。
attackLocationStartX
后面的“Values”。 - akash87extract(message, "x_start", "attackLocationStartX\\s*,\\s*Values\\s*=\\s*(-?\\d+\\.\\d+)")
。它会提取出3.9375
。这是预期的结果吗?还是你需要其他的输出? - Wiktor Stribiżew-?
是什么意思?我以前没见过。 - Todd Shannon