Sed using extended regexp and capture groups
regex, sed
Solution
There is no need to escape braces because `([0-9]*)` is valid statement matching group of symbols.
$> echo "192.168.0.1" | sed -r 's/192\.168\.[0-9]*\.([0-9]*)/192\.168\.15\.\1/g'
192.168.15.1
Problem
I wrote the following sed one liner for substituting the 3rd portion of an IP address. ``` sed 's/192\.168\.[0-9]*\.\([0-9]*\)/192.168.15.\1/g' 192.168.0.1 192.168.15.1 ``` I want to make it lazy so it would replace `192.168.0` with `192.168.15` by using `??` which is extended regexp but when I supply the '-r' option I get the following error. ``` $ sed -r 's/192\.168\.[0-9]*\.\([0-9]*\)/192.168.15.\1/g' sed: -e expression #1, char 44: invalid reference \1 on `s' command's RHS ``` Can you explain what is going on here and how to make an expression lazy whilst using capture groups? Note: I can achieve the example using many different approaches, my question isn't how to solve the example. I am interesting in using sed with exteneded regexp and capture groups.