Using PostgreSQL v.8.2.14, I'm trying to build a regexp with several branches, some of which are case-insensitive, the others not.
Consider the following perl one-liner:
% echo 'foo Foo bar Bar' | perl -pe 's/(foo|(?i:bar))/_\1/g' _foo Foo _bar _Bar I thought I would get there with:
select regexp_replace('foo Foo bar Bar','(foo|((?i)bar)',E'_\\1','g'); But I get: ERROR: invalid regular expression: quantifier operand invalid. Note that the regex_flavor is advanced, and BTW when I put the (?i) at the very beginning of the regexp, then there is no error:
select regexp_replace('foo Foo bar Bar','(?i)(foo|bar)',E'_\\1','g'); _foo _Foo _bar _Bar Any help gladly appreciated.