Using ripgrep's replace option, it is possible to change the output to a capture group:
rg --only-matching --replace '$1' '(\d+) rofl'
--only-matching
or -o
outputs only the part that matches instead of the whole line.
--replace '$1'
or -r
replaces the output by the first capture group.