<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Regular Expression to find and replace a string in a formula in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Regular-Expression-to-find-and-replace-a-string-in-a-formula/m-p/870189#M103332</link>
    <description>&lt;P&gt;yes, regex needs the pattern's parenthesis escaped, at least.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Apr 2025 03:20:39 GMT</pubDate>
    <dc:creator>Craige_Hales</dc:creator>
    <dc:date>2025-04-25T03:20:39Z</dc:date>
    <item>
      <title>Regular Expression to find and replace a string in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Regular-Expression-to-find-and-replace-a-string-in-a-formula/m-p/870088#M103316</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I try to replace one specific part &lt;CODE class=" language-jsl"&gt;As Constant( t Quantile( 1 - 0.1 / 2,&amp;nbsp;&amp;nbsp;&lt;/CODE&gt;in every selected column formula by&amp;nbsp;&lt;CODE class=" language-jsl"&gt;Random t((&lt;/CODE&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I fail in the regex part. I think it could have to do with escaping the brackets. I tried with&amp;nbsp;\!\ but also failed here...&lt;/P&gt;
&lt;P&gt;Could someone debug my code below?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// Select some columns
dt = currentdatatable();
dt &amp;lt;&amp;lt; Get Selected Columns;



//'fix' each selected column formula by manipulating the formula as a string
for each( {col, c}, dt &amp;lt;&amp;lt; Get Column References( dt &amp;lt;&amp;lt; Get Selected Columns ),
		newf = regex(
			char(col &amp;lt;&amp;lt; Get Formula),
			"As Constant( t Quantile( 1 - 0.1 / 2,&amp;nbsp;",
			"Random t((",
			GLOBALREPLACE
		);
		//show(Parse(newf));
		Eval( Eval Expr(
			col &amp;lt;&amp;lt; Set Formula( Expr( Parse(newf) ) )
		) );
);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Apr 2025 16:27:59 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regular-Expression-to-find-and-replace-a-string-in-a-formula/m-p/870088#M103316</guid>
      <dc:creator>Marco_</dc:creator>
      <dc:date>2025-04-24T16:27:59Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression to find and replace a string in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Regular-Expression-to-find-and-replace-a-string-in-a-formula/m-p/870114#M103318</link>
      <description>&lt;P&gt;You can most likely use Substitute or Substitute Into instead of Regex&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here(1); 

dt = open("$SAMPLE_DATA/Big Class.jmp");

new_col = dt &amp;lt;&amp;lt; new column("F", Numeric, Continuous, Formula(
	As Constant(t Quantile(1 - 0.1 / 2, 1, 0))
));

f_expr = new_col &amp;lt;&amp;lt; Get Formula;
f_str = Char(Name Expr(f_expr));

Substitute Into(f_str, "As Constant(t Quantile(1 - 0.1 / 2, ", "Random t((",);
Substitute Into(f_str, "((", "(", "))", ")");

new_col &amp;lt;&amp;lt; Set Formula(Eval(Parse(f_str)));
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 24 Apr 2025 17:55:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regular-Expression-to-find-and-replace-a-string-in-a-formula/m-p/870114#M103318</guid>
      <dc:creator>jthi</dc:creator>
      <dc:date>2025-04-24T17:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: Regular Expression to find and replace a string in a formula</title>
      <link>https://community.jmp.com/t5/Discussions/Regular-Expression-to-find-and-replace-a-string-in-a-formula/m-p/870189#M103332</link>
      <description>&lt;P&gt;yes, regex needs the pattern's parenthesis escaped, at least.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Apr 2025 03:20:39 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regular-Expression-to-find-and-replace-a-string-in-a-formula/m-p/870189#M103332</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2025-04-25T03:20:39Z</dc:date>
    </item>
  </channel>
</rss>

