获取特定字符串之前的数字

时间:2016-06-14 15:41:50

标签: regex r substring

我正在尝试在特定字符串之前获得1位或2位数字。我正在从json解析,我得到以下字符串

Batted ball speed <b>107 mph</b>; distance of <b>399 feet</b> at an angle of <b>5 degrees</b>.
Batted ball speed <b>92 mph</b>; distance of <b>210 feet</b> at an angle of <b>25 degrees</b>.

以下是适用于2位数度的代码。如果我放弃[0-9]中的一个,那么我显然可以得到1位数。

Degrees = substr(feedplay_dat$items$data$description_tracking, regexpr("<b>[0-9]+[0-9] degrees", feedplay_dat$items$data$description_tracking), regexpr("[0-9] degrees", feedplay_dat$items$data$description_tracking))

我的问题是如何更改代码以获得两个学位数,无论它们是1位还是2位,甚至可能是3位数?

修改

可能的副本没有回答我的问题,因为+意味着它必须至少匹配一次。然而,我从那篇文章和弗兰克斯的建议中得到了答案。我最终使用*为零或更多次,并且完美无缺。

0 个答案:

没有答案
相关问题