# Re: string replace/substitute

**URL:** <https://forum.kx.com/t/re-string-replace-substitute/5687>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [July 11, 2008, 8:19am UTC](https://forum.kx.com/t/re-string-replace-substitute/5687 "2008-07-11T08:19:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![simon5](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@simon5](https://forum.kx.com/u/simon5)\
**Post date:** [July 11, 2008, 8:19am UTC](https://forum.kx.com/t/re-string-replace-substitute/5687/1 "2008-07-11T08:19:00Z")

</div>

[https://code.kx.com/trac/wiki/Reference/ssr2008/7/11](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\>

---

<div class="post-metadata">

**Author:** ![Swee\_Heng](https://avatars.discourse-cdn.com/v4/letter/s/e495f1/32.png) [@Swee\_Heng](https://forum.kx.com/u/Swee_Heng)\
**Post date:** [July 14, 2008, 5:13pm UTC](https://forum.kx.com/t/re-string-replace-substitute/5687/2 "2008-07-14T17:13:00Z")

</div>

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](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](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…\>
