select regexp_replace(
E'In most cases regexp_matches() should be used with the g flag,' ||
E'since if you only want\n the first match, it''s easier and more efficient'||
E'to use regexp_match(). \nHowever, regexp_match() only exists in '||
E'PostgreSQL version 10 and up. When working in older\n versions,' ||
E'a common trick is to place a regexp_matches() call in a sub-select,'||
E'for\n example:', E'(.|\n)*?(PostgreSQL version 10)', E'\n');
Return
regexp_replace
----------------------------------------------------------------------------------
+
and up. When working in older +
versions,a common trick is to place a regexp_matches() call in a sub-select,for+
example:
(1 row)
But I'm looking for a generic regex pattern that will capture pattern line (whole line) and following n line.(n as a integer, can be 1 or 2 or 3).
I even tried:
select regexp_replace(
E'In most cases regexp_matches() should be used with the g flag,' ||
E'since if you only want\n the first match, it''s easier and more efficient'||
E'to use regexp_match(). \nHowever, regexp_match() only exists in '||
E'PostgreSQL version 10 and up. When working in older\n versions,' ||
E'a common trick is to place a regexp_matches() call in a sub-select,'||
E'for\n example:', E'.*?(PostgreSQL version 10).*?\n', E'\n');
expected result:
Match one line: The whole line contain string "PostgreSQL version 10" will become newline, others remain the same.
Match two line: The whole line contain string "PostgreSQL version 10" will become newline, the following line will also become new line, others remain the same.