Emulating flexible regex replace

From: Francisco Olarte <folarte(at)peoplecall(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Emulating flexible regex replace
Date: 2014-10-23 16:51:07
Message-ID: CA+bJJbyRE8_kzrCQCd0do=JLA4s-xL1UodDuXMCVgAFnVceVhA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

( Forgot reply all, forwarding a copy, sorry for the noise. )

Hullo.

On Thu, Oct 23, 2014 at 4:03 PM, twoflower <standa(dot)kurik(at)gmail(dot)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.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G Johnston 2014-10-23 17:39:09 Re: Emulating flexible regex replace
Previous Message David G Johnston 2014-10-23 15:45:00 Re: Emulating flexible regex replace