Re: string replace/substitute

https://code.kx.com/trac/wiki/Reference/ssr2008/7/11 Davies Liu <davies.liu>:> try ssr>> Best regards,> Davies Liu>> On Fri, Jul 11, 2008 at 11:09 AM, Jack Andrews wrote:>>>> hi all,>>>> how can i substitue a substring with another. eg. if i have a:>> q) a:“ab""de""""fg”>> then i want a function f:>> q) f[a;“""”;“"”]>> “ab"de""fg”>>>> ta, jack>>>>>>> >></davies.liu>

I’ve recently written a q extension that uses PCRE for regex searchstring and replace. It can be downloaded fromhttp://thesweeheng.wordpress.com/2008/07/14/regular-expressions-for-q/.Feel free to use it. Criticisms are welcomed! :-) q)sub:re 2:(sub;3)q) q)s:“quick brown fox” q)sub[s;“brown”;“BROWN”] “quick BROWN fox” q)sub[s;“\B|\b”;“|”] “|q|u|i|c|k| |b|r|o|w|n| |f|o|x|” q)\t do[1000000;sub[s;“brown”;“BROWN”]] 7141 q)\t do[1000000;ssr[s;“brown”;“BROWN”]] 12236Note: Another q developer implemented a similar PCRE-based q extension(see http://q.o.potam.us) much earlier on.On Jul 11, 3:19 pm, “simon garland” <simon.garl…> wrote:> https://code.kx.com/trac/wiki/Reference/ssr&gt;&gt; 2008/7/11 Davies Liu <davies…>:>> > try ssr>> > Best regards,> > Davies Liu>> > On Fri, Jul 11, 2008 at 11:09 AM, Jack Andrews <effb…> wrote:>> >> hi all,>> >> how can i substitue a substring with another. eg. if i have a:> >> q) a:“ab""de""""fg”> >> then i want a function f:> >> q) f[a;“""”;“"”]> >> “ab"de""fg”>> >> ta, jack</effb…></davies…></simon.garl…>