Normally when you call sed, you can call \1
to reference the submatch number one, i.e.:
<something> | sed "s/<regex>\(<regex>\)<regex>/\1/"
This will just take the middle regex and remove the outer ones.
But what do you do, if you have more then 9 matches? Simply writing \10
doesn't work, because it will be interpreted as take submatch number one and add a zero behind it
.
It's not possible in sed. You'll have to use a different tool.
Here are similar questions on SO:
Circumvent the sed backreference limit \1 through \9.
how to get 10th grouping value in sed?
I'm not sure about SED, but in many languages (javascript, ruby), that have regex implementations that allow for submatching (or backreferencing as it is sometimes called), only support \1
through \9
. \10
is simply not allowed.
Any additional backreferencing would require the use of a more sophisticated parser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With