mirror of
https://github.com/postgres/postgres.git
synced 2025-10-28 11:55:03 +03:00
I made the patch that implements regexp_replace again.
The specification of this function is as follows.
regexp_replace(source text, pattern text, replacement text, [flags
text])
returns text
Replace string that matches to regular expression in source text to
replacement text.
- pattern is regular expression pattern.
- replacement is replace string that can use '\1'-'\9', and '\&'.
'\1'-'\9': back reference to the n'th subexpression.
'\&' : entire matched string.
- flags can use the following values:
g: global (replace all)
i: ignore case
When the flags is not specified, case sensitive, replace the first
instance only.
Atsushi Ogawa
This commit is contained in:
@@ -80,6 +80,13 @@ SELECT SUBSTRING('abcdefg' FROM 'c.e') AS "cde";
|
||||
-- With a parenthesized subexpression, return only what matches the subexpr
|
||||
SELECT SUBSTRING('abcdefg' FROM 'b(.*)f') AS "cde";
|
||||
|
||||
-- PostgreSQL extension to allow using back reference in replace string;
|
||||
SELECT regexp_replace('1112223333', '(\\d{3})(\\d{3})(\\d{4})', '(\\1) \\2-\\3');
|
||||
SELECT regexp_replace('AAA BBB CCC ', '\\s+', ' ', 'g');
|
||||
SELECT regexp_replace('AAA', '^|$', 'Z', 'g');
|
||||
SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'gi');
|
||||
-- invalid option of REGEXP_REPLACE
|
||||
SELECT regexp_replace('AAA aaa', 'A+', 'Z', 'z');
|
||||
|
||||
-- E021-11 position expression
|
||||
SELECT POSITION('4' IN '1234567890') = '4' AS "4";
|
||||
|
||||
Reference in New Issue
Block a user