<?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 Regex backreference followed by a number (unambiguous backreferences) in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/Regex-backreference-followed-by-a-number-unambiguous/m-p/714701#M89804</link>
    <description>&lt;P&gt;I'm scripting something to replace column names based on a regex match. I iterate through all columns and regex regex match with a new string. Works well and handy for shortening col names - except when I am replacing to a string that starts with a number - this is because the backreference gets messed up (\1 becomes \133 in the case below)&lt;/P&gt;&lt;P&gt;In python, there is 'unambious backreference' to work around this. Is there the same in JSL? I read somewhere maybe it uses Perl type backreferences but couldn't find where this is documented.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Peach&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;colName = "COLUMNNAMETEST LONGNAMESHORTEN33339E0HS KEEPTHIS";
Rename_regx = "LONGNAMESHORTEN2339E0HS111";
Rename_to = "39E0H";

newname=Regex( colName,
	"(.*?)(" || Rename_regx || ")(.*)", // match
	"\1" || Rename_to || "\3") // replace match with

//	"\g&amp;lt;1&amp;gt;" || Rename_to || "\g&amp;lt;3&amp;gt;") // python like unambiguous doesn't owrk&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 10 Jan 2024 23:17:03 GMT</pubDate>
    <dc:creator>jetpeach</dc:creator>
    <dc:date>2024-01-10T23:17:03Z</dc:date>
    <item>
      <title>Regex backreference followed by a number (unambiguous backreferences)</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-backreference-followed-by-a-number-unambiguous/m-p/714701#M89804</link>
      <description>&lt;P&gt;I'm scripting something to replace column names based on a regex match. I iterate through all columns and regex regex match with a new string. Works well and handy for shortening col names - except when I am replacing to a string that starts with a number - this is because the backreference gets messed up (\1 becomes \133 in the case below)&lt;/P&gt;&lt;P&gt;In python, there is 'unambious backreference' to work around this. Is there the same in JSL? I read somewhere maybe it uses Perl type backreferences but couldn't find where this is documented.&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Peach&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;colName = "COLUMNNAMETEST LONGNAMESHORTEN33339E0HS KEEPTHIS";
Rename_regx = "LONGNAMESHORTEN2339E0HS111";
Rename_to = "39E0H";

newname=Regex( colName,
	"(.*?)(" || Rename_regx || ")(.*)", // match
	"\1" || Rename_to || "\3") // replace match with

//	"\g&amp;lt;1&amp;gt;" || Rename_to || "\g&amp;lt;3&amp;gt;") // python like unambiguous doesn't owrk&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Jan 2024 23:17:03 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-backreference-followed-by-a-number-unambiguous/m-p/714701#M89804</guid>
      <dc:creator>jetpeach</dc:creator>
      <dc:date>2024-01-10T23:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Regex backreference followed by a number (unambiguous backreferences)</title>
      <link>https://community.jmp.com/t5/Discussions/Regex-backreference-followed-by-a-number-unambiguous/m-p/714744#M89807</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;colName = "COLUMNNAMETEST LONG\1NAMESHORTEN2339E0HS111 KEEPTHIS";
Rename_regx = substitute("LONG\1NAMESHORTEN2339E0HS111","\","\\");
Rename_to = "39E \1 0H";

// \Q starts a sequence that ignores escapes
newname=Regex( colName,
	"(.*?)(" || Rename_regx || ")(.*)", // match
	"\1\Q" || Rename_to || "\E\3"); // replace match with
show(newname); // newname = "COLUMNNAMETEST 39E \1 0H KEEPTHIS";
// notice: 
//   \Q begins "quoting" and \E ends it
//   the \Q has a side effect of ending the \1 (which is what you asked)
//   the \1 in the replacement is NOT expanded inside the \Q...\E
//   at the very top, it takes care of escaping any escapes with substitute,
//   which *could* be an issue

// what else? upper and lower case:
// \L begin lower casing 
// \U begin upper casing
// \E ends *all* \L, \U, or \Q
show(regex("aBcDEf","(..)(..)(..)","\1\L \2 \U\3"));//"aB cd EF"
// \l (lower case L) lower case the next character
// \u upper case the next character
show(regex("ABcdEF","(..)(..)(..)","\1 \u\2 \l\3"));//"AB Cd eF"
// the Q, L, and U modes share a common E (end)
// the q and l are not persistent and only apply to the next character.
// upper/lower is probably very ASCII specific, no Unicode magic.

// this is poorly documented here: https://www.jmp.com/support/help/en/17.2/index.shtml#page/jmp/escaped-characters-in-regular-expressions.shtml
// somehow all the escapes have been lumped together in the worst possible way.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;edit: there are two parameters to the regex() function that use escapes. Parameter 2 is the pattern and uses escapes the way most people expect, and the \Q \U \L \E \u \l do &lt;EM&gt;not&lt;/EM&gt; belong there. Parameter 3 is the replacement, and the \Q \U \L \E \u \l &lt;EM&gt;can&lt;/EM&gt; be used there. Backreferences \1 \2 \3 ... can be used in both parm2 and parm3.&lt;/P&gt;
&lt;P&gt;edit 14aug2025: actually, \U\u\L\l can be used in parameter 2 and match a single character: u upper, U not upper, l lower and L not lower. Also \A and \Z match the beginning and end positions.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Aug 2025 23:47:20 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/Regex-backreference-followed-by-a-number-unambiguous/m-p/714744#M89807</guid>
      <dc:creator>Craige_Hales</dc:creator>
      <dc:date>2025-08-14T23:47:20Z</dc:date>
    </item>
  </channel>
</rss>

