Skip to main content
added 230 characters in body
Source Link
hwnd
  • 70.5k
  • 4
  • 97
  • 133

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+'

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

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+'
deleted 5 characters in body
Source Link
hwnd
  • 70.5k
  • 4
  • 97
  • 133

The Named Capturing Group is useless in contextnot 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

The Named Capturing Group is useless in context 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

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
Source Link
hwnd
  • 70.5k
  • 4
  • 97
  • 133

The Named Capturing Group is useless in context 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