Attribute "match.length"in regexprseems to do the job (-1 is used to distinguish match from zero-width matches such as lookaheads)
attr(regexpr(",+$", x), "match.length")
Another option (with input from @JasonAizkalns) would be
nchar(x) - nchar(gsub(",+$", "", x))
Or using the package stringiin conjunction with ncharwhen specifying , keepNA = TRUE(thus, no matches will be specified as NAs)
library(stringi)
nchar(stri_extract_all_regex(x, ",+$"), keepNA = TRUE)
## [1] 2  1 NA  3
 source
share