Re: [GENERAL] Emulating flexible regex replace

2014-10-25 Thread Francisco Olarte
Hi: On Fri, Oct 24, 2014 at 6:13 PM, twoflower wrote: > It works very vell. However, I am not completely satisfied with i as it's > unnecessarily loading larger data set than it absolutely must. Besides, I'd > also like to get some experience in DB programming. That's why the PL/Perl > way

Re: [GENERAL] Emulating flexible regex replace

2014-10-24 Thread twoflower
Thank you Francisco. In fact, I am already solving part of the problem in my application - fetching from the DB the records matching the source pattern and then filtering them in the application's memory by matching against the target pattern, with the references replaced (it's a breeze in C#). I

Re: [GENERAL] Emulating flexible regex replace

2014-10-24 Thread Francisco Olarte
Hi: On Fri, Oct 24, 2014 at 8:24 AM, twoflower wrote: > Thank you Francisco, that's a clever idea. However, I don't think this > would > reduce the complexity since the target pattern can contain > > 1) regular back-references (referencing to matches of its own) > 2) the special source text refe

Re: [GENERAL] Emulating flexible regex replace

2014-10-23 Thread twoflower
Thank you Francisco, that's a clever idea. However, I don't think this would reduce the complexity since the target pattern can contain 1) regular back-references (referencing to matches of its own) 2) the special source text references I mentioned Obviously, these will have to be written in a di

Re: [GENERAL] Emulating flexible regex replace

2014-10-23 Thread blackbee045
This yields a successful match since $1 in the /target pattern/ is replaced > by "123" from the first captured group in *source* and the resulting > string, > "123 target text", matches the /target pattern/. > I would like to execute a query which for a given /source pattern/ and > /target pat

Re: [GENERAL] Emulating flexible regex replace

2014-10-23 Thread David G Johnston
David G Johnston wrote > > twoflower wrote >> Source: 123 source text >> Target: 123 target text >> Source pattern: ([0-9]+) source text >> Target pattern: $1 target text >> >> Still, isn't there some super clever way to do that? > You use "\1" instead of "$1" > > SELECT regexp_replace('123 abc'

[GENERAL] Emulating flexible regex replace

2014-10-23 Thread Francisco Olarte
( Forgot reply all, forwarding a copy, sorry for the noise. ) Hullo. On Thu, Oct 23, 2014 at 4:03 PM, twoflower 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 patt

Re: [GENERAL] Emulating flexible regex replace

2014-10-23 Thread David G Johnston
twoflower wrote > Source: 123 source text > Target: 123 target text > Source pattern: ([0-9]+) source text > Target pattern: $1 target text > > Still, isn't there some super clever way to do that? You use "\1" instead of "$1" SELECT regexp_replace('123 abc','(\d+)\s(\w+)','\1 def'); --output: '1

Re: [GENERAL] Emulating flexible regex replace

2014-10-23 Thread Tom Lane
twoflower writes: > Supposing *source* matches the /source pattern/, the $/n/ expressions inside > the /target pattern/ correspond to the captured groups inside *source*. > Example: > Source: 123 source text > Target: 123 target text > Source pattern: ([0-9]+) source text > Target pattern: $1 ta

[GENERAL] Emulating flexible regex replace

2014-10-23 Thread twoflower
Hello, 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: