How to str_extract percentages in R?
问题 From this string border-color:#002449;left:74.4%top;37%; I would like to make the first percentage 74.4% a variable called X and the second percentage 37% a variable called Y . I have tried to play around with this regex "^.*?(\\d+)%.*" but this takes out the % sign and only extracts the second 4 from 74.4 Any help will be appreciated. Please let me know if any further information is needed. 回答1: s <- "border-color:#002449;left:74.4%top;37%;" regmatches(s, gregexpr("\\d+(\\.\\d+){0,1}%", s))[