Working for the first time with Postgres flavor regular expressions and stumped on it's behavior here.
Input: 'xxxaaabc'
Expected: 'xxxaaazzzbc'
Logic: Match M a's, capture group, and add 'zzz' directly after the sequence
Attempts:
select regexp_replace('aaabc','(?!\Sa+)','zzz','i')
Result: zzzxxxaaabc
select regexp_replace('aaabc','(?!\Sa+)','zzz','i')
Result: xxxazzzaabc
select select regexp_replace('xxxaaabc','(?!=a+)','zzz','i')
Result: zzzxxxaaabc
This one seems to get pretty close regexp_replace('aaabc','(?!\Sa+)','zzz','i'), but the repetition of a's isn't working.
select regexp_replace('xxxaaabc','(a+)','\1zzz','i') AS Result;(demo)