sed -n ‘s/^.*\(<regex_pattern>\).*$/\1/p’ filename
This sed means substitute the whole line with the ‘\1’ (i.e. the matched pattern) and print the line. So it will print the text (not the whole line) which matches <regex_pattern>.
We can also use perl: perl -i -p0e ‘s/abc\n efg/opq\n rst/’ filename