Emulating flexible regex replace - Mailing list pgsql-general

From Francisco Olarte
Subject Emulating flexible regex replace
Date
Msg-id CA+bJJbyRE8_kzrCQCd0do=JLA4s-xL1UodDuXMCVgAFnVceVhA@mail.gmail.com
Whole thread Raw
Responses Re: Emulating flexible regex replace
List pgsql-general
( Forgot reply all, forwarding a copy, sorry for the noise. )

Hullo.

On Thu, Oct 23, 2014 at 4:03 PM, twoflower <standa.kurik@gmail.com> wrote:

my scenario is this: I have a *SEGMENT* table with two text fields, *source*
and *target*. From the user, I get the following input:

/source pattern/
/target pattern/

Where both patterns are regexes and moreover the target pattern contains
references to the source in the following way:

Supposing *source* matches the /source pattern/, the $/n/ expressions inside
the /target pattern/ correspond to the captured groups inside *source*.


*If* you have some available char sequence which is not going to be in any of them and your regexp are not too esoteric, you could just try to match source || 'XyZzYX' || target against source_pattern || 'XyZzYX' || target_pattern, replace separator as needed.

If your patterns are ( not ) anchored you may need to insert some .* / ^ / $ and multiline modifiers, but this normally works for me ( in perl normally, but should be easy to do ).

Your performance maybe really bad if your tables are big and you have no more conditions, but any query with general patterns tend to behave this way.

Francisco Olarte.


pgsql-general by date:

Previous
From: David G Johnston
Date:
Subject: Re: Emulating flexible regex replace
Next
From: David G Johnston
Date:
Subject: Re: Emulating flexible regex replace