The Named Capturing Group is not necessary here. Using the -o
option shows only the matching part that matches the pattern, so with the combination of the Positive Lookbehind assertion and the -o
command line option, you do not need a capturing group. The lookbehind does not consume characters in the string, but only asserts whether a match is possible or not.
echo 'foo.com/check?var=test&start=11' | grep -Po '(?<=start=)\d+'
# 11
Alternatively, \K
resets the starting point of the reported match and any previously consumed characters are no longer included. e.g. throws away everything that it has matched up to that point.
grep -Po 'start=\K\d+'