$RegexReplace: Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
 
(37 intermediate revisions by 6 users not shown)
Line 1: Line 1:
{{DISPLAYTITLE:$RegexReplace}}
{{DISPLAYTITLE:$RegexReplace}}
<span class="pageSubtitle"><section begin="desc" />Replace matching strings<section end="desc" /></span>
<span class="pageSubtitle">Replace matching strings</span>


<p class="warning">Most Sirius $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $RegexReplace function is the [[RegexReplace (String function)]].</p>
<p class="warn"><b>Note:</b> Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the <var>$RegexReplace</var> function is the <var>[[RegexReplace (String function)|RegexReplace]]</var> <var>String</var> function. </p>


This function searches a given string for matches of a regular expression, and it replaces found matches with or according to a specified replacement string. The function stops after the first match and replace, or it can continue searching and replacing until no more matches are found. The function is available as of Version 6.9 of the ''[[Sirius Mods]]''.  
This function searches a given string for matches of a regular expression, and it replaces found matches with or according to a specified replacement string. The function stops after the first match and replace, or it can continue searching and replacing until no more matches are found.  


Matches are obtained according to the "rules" of regular expression matching (information about the rules observed is provided in ).  
Matches are obtained according to the "rules" of regular expression matching (information about the rules observed is provided in [[Regex processing#Regex rules|Regex rules]]).
 
<var>$RegexReplace</var> accepts three required and two optional arguments, and it returns a string. It is also [[Calling Sirius Mods $functions|callable]]. Specifying an invalid argument results in request cancellation.


==Syntax==
==Syntax==
<p class="syntax"><section begin="syntax" /> outStr = $RegexReplace(inStr, regex, replacement, -
<p class="syntax">outStr = $RegexReplace(inStr, regex, replacement, [options], [%status])
[options], [%status])
<section end="syntax" /></p>
<p class="caption">$RegexReplace Function
</p>
</p>
<p class="caption">'''outStr''' is a string set to the value of '''inStr''' with each matched substring replaced by the value of '''replacement'''.</p>


$RegexReplace accepts three required and two optional arguments, and it returns a string. It is also callable . Specifying an invalid argument results in request cancellation.
===Syntax terms===
<table>
<tr><th>outStr</th>
<td>A string set to the value of <var class="term">inStr</var> with each matched substring replaced by the value of <var class="term">replacement</var>.</td></tr>
<tr><th>inStr</th>
<td>the input string, to which the regular expression <var class="term">regex</var> is applied. This is a required argument. </td></tr>


<ul>
<tr><th>regex</th>
<li>The first argument is the input string, to which the regular expression '''regex''' is applied. This is a required argument.
<td>a string that is interpreted as a regular expression and that is applied to the <var class="term">inStr</var> argument to find the one or more <var class="term">inStr</var> substrings matched by <var class="term">regex</var>. This is a required argument. </td></tr>
<li>The second argument is a string that is interpreted as a regular expression and that is applied to the '''inStr''' argument to find the one or more '''inStr''' substrings matched by '''regex'''. This is a required argument.  
<li>The third argument is the string that replaces the substrings of '''inStr''' that '''regex''' matches. This is a required argument.


Except when the <tt>A</tt> option is specified (as described below for the fourth argument), you can include markers in the '''replacement''' value to indicate where to insert corresponding captured strings -- strings matched by capturing groups (parenthesized subexpressions) in '''regex''', if any.  
<tr><th>replacement</th>
<td>The string that replaces the substrings of <var class="term">inStr</var> that <var class="term">regex</var> matches. This is a required argument.  


As in Perl, these markers are in the form <tt>$n</tt>, where '''n''' is the number of the capture group, and 1 is the number of the first capture group. '''n''' must not be 0 or contain more than 9 digits.  
Except when the <code>A</code> option is specified (as described below for the <var class="term">options</var> argument), you can include markers in the <var class="term">replacement</var> value to indicate where to insert corresponding captured strings &mdash; strings matched by capturing groups (parenthesized subexpressions) in <var class="term">regex</var>, if any.  


If a capturing group makes no matches (is positional, for example), or if there was no '''n'''th capture group corresponding to the <tt>$n</tt> marker in a replacement string, the value of <tt>$n</tt> used in the replacement string is the empty string.  
As in Perl, these markers are in the form <code>$n</code>, where <i>n</i> is the number of the capture group, and 1 is the number of the first capture group. <i>n</i> must not be 0 or contain more than 9 digits.  


<tt>xxx$1</tt> is an example of a valid replacement string, and <tt>$0yyy</tt> is an example of a '''non'''-valid one.
If a capturing group makes no matches (is positional, for example), or if there was no <var class="term">n</var>th capture group corresponding to the <tt>$n</tt> marker in a replacement string, the value of <code>$n</code> used in the replacement string is the empty string.
Or you can use the format <tt>$mn</tt>, where '''m''' is one of the following modifiers:


<table class="syntaxTable">
<code>xxx$1</code> is an example of a valid replacement string, and <code>$0yyy</code> is an example of a <strong>non-valid</strong> one.
<tr><th>U or u</th>
Or you can use the format <code>$mn</code>, where <var class="term">m</var> is one of the following modifiers:
<table>
<tr><th><var>U</var> or <var class="camel">u</var></th>
<td>Specifies that the specified captured string should be uppercased when inserted.</td></tr>
<td>Specifies that the specified captured string should be uppercased when inserted.</td></tr>
<tr><th>L or l</th>
 
<tr><th><var>L</var> or <var class="camel">l</var></th>
<td>Indicates that the captured string should be lowercased when inserted.
<td>Indicates that the captured string should be lowercased when inserted.
</td></tr></table>
</td></tr></table>


The only characters you can escape in a replacement string are dollar sign (<tt>$</tt>), backslash (<tt>\</tt>), and the digits <tt>0</tt> through <tt>9</tt>. So only these escapes are respected:  
The only characters you can escape in a replacement string are dollar sign (<tt>$</tt>), backslash (<tt>\</tt>), and the digits <tt>0</tt> through <tt>9</tt>. So only these escapes are respected:  
<li>.\\</tt>, <tt>\$</tt>, and <tt>\0</tt> through <tt>\9</tt>. No other escapes are allowed in a replacement string -- this includes "shorthand" escapes like <tt>\d</tt> -- and an "unaccompanied" backslash (<tt>\</tt>) is an error.  
<tt>.\\</tt>, <tt>\$</tt>, and <tt>\0</tt> through <tt>\9</tt>. No other escapes are allowed in a replacement string &mdash; this includes "shorthand" escapes like <tt>\d</tt> &#x2014; and an "unaccompanied" backslash (<tt>\</tt>) is an error.  


For example, since the scan for the number that accompanies the meta-$ stops at the first non-numeric, you use <tt>1$1\2</tt> to indicate that the first captured string should go between the numbers 1 and 2 in the replacement string.  
For example, since the scan for the number that accompanies the meta-$ stops at the first non-numeric, you use <tt>1$1\2</tt> to indicate that the first captured string should go between the numbers 1 and 2 in the replacement string. </td></tr>
<li>The fourth argument is an optional string of options. The options are single letters, which may be specified in uppercase or lowercase, in any combination, and separated by blanks or not separated. For more information about these options, see


<table class="syntaxTable">
<tr><th>options</th>
<tr><th>I</th>
<td>An optional string of options. The options are single letters, which may be specified in uppercase or lowercase, in any combination, and separated by blanks or not separated. For more information about these options, see [[Regex processing#Common_regex_options|Common regex options]].
<td>Do case-insensitive matching between '''string''' and '''regex'''.</td></tr>
<tr><th>S</th>
<td>Dot-All mode: a dot (".") can match any character, including carriage return and linefeed.</td></tr>
<tr><th>M</th>
<td>Multi-line mode: let anchor characters match end-of-line indicators '''wherever''' the indicator appears in the input string. M mode is ignored if C (XML Schema) mode is specified.</td></tr>
<tr><th>C</th>
<td>Do the match according to XML Schema regex rules. Each regex is implicitly anchored at the beginning and end, and no characters serve as anchors. For more information,</td></tr>
<tr><th>G</th>
<td>Replace every occurrence of the match, not just (as in non-G mode) the first matched substring only.</td></tr>
<tr><th>A</th>
<td>Copy the '''replacement''' string as is. Do not recognize escapes; interpret a <tt>$n</tt> combination as a literal and '''not''' as a special marker; and so on.
</td></tr>
</td></tr>
</table>


<li>The fifth argument is optional; if specified, it is set to an integer error code. These values are possible:
<tr><th>%status</th>
<td>An optional, integer status code. These values are possible:
<table class="syntaxTable">


<table class="syntaxTable">
<tr><th><i>n</i></th>
<tr><th><i>n</i></th>
<td>The number of replacements made.</td></tr>
<td>The number of replacements made.</td></tr>
<tr><th>0</th>
 
<td>No match: '''inStr''' was not matched by '''regex'''.</td></tr>
<tr><th><var>0</var></th>
<tr><th>-5</th>
<td>No match: <var class="term">inStr</var> was not matched by <var class="term">regex</var>.</td></tr>
<td>An invalid '''replacement''' string. For example, an invalid escape sequence, or a <tt>$</tt> followed by a non-number, by a <tt>0</tt> or by no digits, or by more than 9 digits.</td></tr>
 
<tr><th>-1<i>nnn</i></th>
<tr><th><var>-5</var></th>
<td>The pattern in '''regex''' is invalid. <i>nnn</i>, the absolute value of the return minus 1000, gives the 1-based position of the character being scanned when the error was discovered. The value for an error occurring at end-of-string is the length of the string + 1. Prior to Version 7.0 of the ''[[Sirius Mods]]'', an invalid regex results in a '''status''' value of <tt>-1</tt>.
<td>An invalid <var class="term">replacement</var> string. For example, an invalid escape sequence, or a <tt>$</tt> followed by a non-number, by a <tt>0</tt> or by no digits, or by more than 9 digits.</td></tr>
</td></tr>
 
<tr><th><var>-1</var><i>nnn</i></th>
<td>The pattern in <var class="term">regex</var> is invalid. <i>nnn</i>, the absolute value of the return minus 1000, gives the 1-based position of the character being scanned when the error was discovered. The value for an error occurring at end-of-string is the length of the string + 1. </td></tr>
</table>
</table>


<blockquote> If you omit this argument and a negative '''status''' value is to be returned, the run is cancelled.</blockquote>
<p class="note"><b>Note:</b> If you omit this argument and a negative <var class="term">%status</var> value is to be returned, the run is cancelled.</p></td></tr>
</ul>
</table>


==Notes==
==Usage notes==
<ul>
<li>It is strongly recommended that you protect your environment from regex processing demands on PDL and STBL space by setting, say, <code>UTABLE LPDLST 3000</code> and <code>UTABLE LSTBL 9000</code>. For further discussion of this,


<ul>
<li>It is strongly recommended that you protect your environment from regex processing demands on PDL and STBL space by setting, say, <tt>UTABLE LPDLST 3000</tt> and <tt>UTABLE LSTBL 9000</tt>. For further discussion of this,
<li>$RegexReplace is Longstring-capable. Its string inputs and outputs are considered Longstrings for expression-compilation purposes, and they have standard Longstring truncation behavior: truncation by assignment results in request cancellation. For more information,  
<li>$RegexReplace is Longstring-capable. Its string inputs and outputs are considered Longstrings for expression-compilation purposes, and they have standard Longstring truncation behavior: truncation by assignment results in request cancellation. For more information,  
<li>Within a regex, characters enclosed by a pair of unescaped parentheses form a "subexpression". A subexpression is a capturing group if the opening parenthesis is '''not''' followed by a question mark (<tt>?</tt>). A capturing group that is nested within a non-capturing subexpression is still a capturing group.
<li>In Perl, <tt>$n</tt> markers (<tt>$1</tt>, for example) enclosed in single quotes are treated as literals instead of as "that which was captured by the first capturing parentheses." $RegexReplace uses the <tt>A</tt> option of the Option argument for this purpose.
<li>A regex may "succeed" but match no characters. For example, a quantifier like <tt>?</tt> is allowed by definition to match no characters, though it tries to match one. $RegexReplace honors such a zero-length match by substituting the specified replacement string at the current position. If the global option is in effect, the regex is then applied again one position to the right in the input string, and again, until the end of the string. The regex <tt>9?</tt> globally applied to the string <tt>abc</tt> with a comma-comma (<tt>,,</tt>) replacement string results in this output string: :lit.,,a,,b,,c,,:elit..
<li>Say you want to supply end tags to items of of the form <tt><img foo="bar"></tt>, converting them to <tt><img foo="bar"></img></tt>. You decide to use the following regex to capture <tt>img</tt> tags that have attributes:
<p class="code"> (<img .*>)
</p>


And you use the following replacement string to replace the captured string with the captured string plus an appended <tt></img></tt>:
<li>Within a regex, characters enclosed by a pair of unescaped parentheses form a "subexpression". A subexpression is a capturing group if the opening parenthesis is <strong>not</strong> followed by a question mark (<tt>?</tt>). A capturing group that is nested within a non-capturing subexpression is still a capturing group.
 
<li>In Perl, <tt>$n</tt> markers (<tt>$1</tt>, for example) enclosed in single quotes are treated as literals instead of as "that which was captured by the first capturing parentheses." <var>$RegexReplace</var> uses the <tt>A</tt> option of the Option argument for this purpose.
<li>A regex may "succeed" but match no characters. For example, a quantifier like <tt>?</tt> is allowed by definition to match no characters, though it tries to match one. <var>$RegexReplace</var> honors such a zero-length match by substituting the specified replacement string at the current position. If the global option is in effect, the regex is then applied again one position to the right in the input string, and again, until the end of the string. The regex <tt>9?</tt> globally applied to the string <tt>abc</tt> with a comma-comma (<tt>,,</tt>) replacement string results in this output string: <code>,,a,,b,,c,,</code>.


<p class="code"> $1</img>
<li>Say you want to supply end tags to items of of the form <code><img foo="bar"></code>, converting them to <code><img foo="bar"></img></code>. You decide to use the following regex to capture <code>img</code> tags that have attributes:
<p class="code">(<img .*>)
</p>
</p>
 
<p>
And you use the following replacement string to replace the captured string with the captured string plus an appended <code></img></code>:
</p>
<p class="code">$1</img>
</p>
<p>
However, if the regex above is applied to the string  
However, if the regex above is applied to the string  
<tt><body><img src="foo" width="24"></body></tt>, the end tag <tt></img></tt> is not inserted after the first closing angle bracket (<tt>></tt>) after <tt>"24"</tt> as you want. Instead, the matched string greedily extends to the second closing angle bracket, and the tag <tt></img></tt> is positioned at the end:
<code><body><img src="foo" width="24"></body></code>, the end tag <code></img></code> is not inserted after the first closing angle bracket (<code>></code>) after <code>"24"</code> as you want. Instead, the matched string greedily extends to the second closing angle bracket, and the tag <code></img></code> is positioned at the end:  
 
<p class="code"> <body><img src="foo" width="24"></body></img>
</p>
</p>
 
<p class="code"><body><img src="foo" width="24"></body></img>
One remedy for this situation is to use the following regex, which employs a negated character class to match non-closing-bracket characters:
<p class="code"> (<img [&circ.>]*>)
</p>
</p>
 
<p>
This regex does not extend beyond the first closing angle bracket in the target input string, and the resulting output string is:
One remedy for this situation is to use the following regex, which employs a negated character class to match non-closing-bracket characters: </p>
<p class="code"> <body><img src="foo" width="24"></img></body>
<p class="code">(<img [&circ;>]*>)
</p>
</p>
<p>
This regex does not extend beyond the first closing angle bracket in the target input string, and the resulting output string is: </p>
<p class="code"><body><img src="foo" width="24"></img></body>
</p></li>


<li>For information about additional methods and $functions that support regular expressions,
<li>For information about additional methods and $functions that support regular expressions, see [[Regex processing]]. </li>
</ul>
</ul>


In the following example, the regex <tt>(5.)</tt> is applied repeatedly (global option) to the string <tt>5A5B5C5D5E</tt> to replace the uppercase letters with their lowercase counterparts. The <tt>$L1</tt> '''%relacement''' value makes the replacement string equal to whatever is matched by the capturing group, <tt>(5.)</tt>, in the regex (the <tt>L</tt> causes the lowercase versions of the captured letters to be used).
==Examples==
In the following example, the regex <code>(5.)</code> is applied repeatedly (global option) to the string <code>5A5B5C5D5E</code> to replace the uppercase letters with their lowercase counterparts. The <code>$L1</code> <code>%replacement</code> value makes the replacement string equal to whatever is matched by the capturing group, <code>(5.)</code>, in the regex (the <code>L</code> causes the lowercase versions of the captured letters to be used).


<p class="code"> Begin
<p class="code">Begin
%regex Longstring
%regex Longstring
%inStr Longstring
%inStr Longstring
%replacement Longstring
%replacement Longstring
%outStr Longstring
%outStr Longstring
%opt string len 10
%opt string len 10
%status float
%status float
   
   
%inStr='5A5B5C5D5E'
%inStr='5A5B5C5D5E'
%regex='(5.)'
%regex='(5.)'
%replacement='$L1'
%replacement='$L1'
%opt='g'
%opt='g'
%outStr = $RegexReplace (%inStr, %regex, %replacement, -
%outStr = $RegexReplace (%inStr, %regex, %replacement, -
%opt, %status)
%opt, %status)
Print '%RegexReplace: status = ' %status
Print '%RegexReplace: status = ' %status
Print 'OutputString: ' %outStr
Print 'OutputString: ' %outStr
End
End
</p>
</p>


The example result is:
The example result is:
<p class="code"> %RegexReplace: status = 5
<p class="output">%RegexReplace: status = 5
OutputString: 5a5b5c5d5e
OutputString: 5a5b5c5d5e
</p>
</p>


The non-capturing regex <tt>5.</tt> matches and replaces the same substrings as the capturing group <tt>(5.)</tt>, but <tt>(5.)</tt> is used above to take advantage of the self-referring marker for the replacement string, <tt>$L1</tt>, which is valid only for capturing groups.
The non-capturing regex <code>5.</code> matches and replaces the same substrings as the capturing group <code>(5.)</code>, but <code>(5.)</code> is used above to take advantage of the self-referring marker for the replacement string, <code>$L1</code>, which is valid only for capturing groups.  
 
This $function is available as of Version 6.9.


==Products authorizing {{PAGENAMEE}}==
<ul class="smallAndTightList">
<ul class="smallAndTightList">
<li>[[Sirius $Functions]]
<li>[[Sirius Functions]] </li>
</ul>
</ul>
<p class="caption">Products authorizing $RegexReplace
</p>


[[Category:$Functions|$RegexReplace]]
[[Category:$Functions|$RegexReplace]]
[[Category:Regular expression processing]]

Latest revision as of 17:06, 21 January 2022

Replace matching strings

Note: Many $functions have been deprecated in favor of Object Oriented methods. The OO equivalent for the $RegexReplace function is the RegexReplace String function.

This function searches a given string for matches of a regular expression, and it replaces found matches with or according to a specified replacement string. The function stops after the first match and replace, or it can continue searching and replacing until no more matches are found.

Matches are obtained according to the "rules" of regular expression matching (information about the rules observed is provided in Regex rules).

$RegexReplace accepts three required and two optional arguments, and it returns a string. It is also callable. Specifying an invalid argument results in request cancellation.

Syntax

outStr = $RegexReplace(inStr, regex, replacement, [options], [%status])

Syntax terms

outStr A string set to the value of inStr with each matched substring replaced by the value of replacement.
inStr the input string, to which the regular expression regex is applied. This is a required argument.
regex a string that is interpreted as a regular expression and that is applied to the inStr argument to find the one or more inStr substrings matched by regex. This is a required argument.
replacement The string that replaces the substrings of inStr that regex matches. This is a required argument.

Except when the A option is specified (as described below for the options argument), you can include markers in the replacement value to indicate where to insert corresponding captured strings — strings matched by capturing groups (parenthesized subexpressions) in regex, if any.

As in Perl, these markers are in the form $n, where n is the number of the capture group, and 1 is the number of the first capture group. n must not be 0 or contain more than 9 digits.

If a capturing group makes no matches (is positional, for example), or if there was no nth capture group corresponding to the $n marker in a replacement string, the value of $n used in the replacement string is the empty string.

xxx$1 is an example of a valid replacement string, and $0yyy is an example of a non-valid one. Or you can use the format $mn, where m is one of the following modifiers:

U or u Specifies that the specified captured string should be uppercased when inserted.
L or l Indicates that the captured string should be lowercased when inserted.

The only characters you can escape in a replacement string are dollar sign ($), backslash (\), and the digits 0 through 9. So only these escapes are respected: .\\, \$, and \0 through \9. No other escapes are allowed in a replacement string — this includes "shorthand" escapes like \d — and an "unaccompanied" backslash (\) is an error.

For example, since the scan for the number that accompanies the meta-$ stops at the first non-numeric, you use 1$1\2 to indicate that the first captured string should go between the numbers 1 and 2 in the replacement string.
options An optional string of options. The options are single letters, which may be specified in uppercase or lowercase, in any combination, and separated by blanks or not separated. For more information about these options, see Common regex options.
%status An optional, integer status code. These values are possible:
n The number of replacements made.
0 No match: inStr was not matched by regex.
-5 An invalid replacement string. For example, an invalid escape sequence, or a $ followed by a non-number, by a 0 or by no digits, or by more than 9 digits.
-1nnn The pattern in regex is invalid. nnn, the absolute value of the return minus 1000, gives the 1-based position of the character being scanned when the error was discovered. The value for an error occurring at end-of-string is the length of the string + 1.

Note: If you omit this argument and a negative %status value is to be returned, the run is cancelled.

Usage notes

  • It is strongly recommended that you protect your environment from regex processing demands on PDL and STBL space by setting, say, UTABLE LPDLST 3000 and UTABLE LSTBL 9000. For further discussion of this,
  • $RegexReplace is Longstring-capable. Its string inputs and outputs are considered Longstrings for expression-compilation purposes, and they have standard Longstring truncation behavior: truncation by assignment results in request cancellation. For more information,
  • Within a regex, characters enclosed by a pair of unescaped parentheses form a "subexpression". A subexpression is a capturing group if the opening parenthesis is not followed by a question mark (?). A capturing group that is nested within a non-capturing subexpression is still a capturing group.
  • In Perl, $n markers ($1, for example) enclosed in single quotes are treated as literals instead of as "that which was captured by the first capturing parentheses." $RegexReplace uses the A option of the Option argument for this purpose.
  • A regex may "succeed" but match no characters. For example, a quantifier like ? is allowed by definition to match no characters, though it tries to match one. $RegexReplace honors such a zero-length match by substituting the specified replacement string at the current position. If the global option is in effect, the regex is then applied again one position to the right in the input string, and again, until the end of the string. The regex 9? globally applied to the string abc with a comma-comma (,,) replacement string results in this output string: ,,a,,b,,c,,.
  • Say you want to supply end tags to items of of the form <img foo="bar">, converting them to <img foo="bar"></img>. You decide to use the following regex to capture img tags that have attributes:

    (<img .*>)

    And you use the following replacement string to replace the captured string with the captured string plus an appended </img>:

    $1</img>

    However, if the regex above is applied to the string <body><img src="foo" width="24"></body>, the end tag </img> is not inserted after the first closing angle bracket (>) after "24" as you want. Instead, the matched string greedily extends to the second closing angle bracket, and the tag </img> is positioned at the end:

    <body><img src="foo" width="24"></body></img>

    One remedy for this situation is to use the following regex, which employs a negated character class to match non-closing-bracket characters:

    (<img [ˆ>]*>)

    This regex does not extend beyond the first closing angle bracket in the target input string, and the resulting output string is:

    <body><img src="foo" width="24"></img></body>

  • For information about additional methods and $functions that support regular expressions, see Regex processing.

Examples

In the following example, the regex (5.) is applied repeatedly (global option) to the string 5A5B5C5D5E to replace the uppercase letters with their lowercase counterparts. The $L1 %replacement value makes the replacement string equal to whatever is matched by the capturing group, (5.), in the regex (the L causes the lowercase versions of the captured letters to be used).

Begin %regex Longstring %inStr Longstring %replacement Longstring %outStr Longstring %opt string len 10 %status float %inStr='5A5B5C5D5E' %regex='(5.)' %replacement='$L1' %opt='g' %outStr = $RegexReplace (%inStr, %regex, %replacement, - %opt, %status) Print '%RegexReplace: status = ' %status Print 'OutputString: ' %outStr End

The example result is:

%RegexReplace: status = 5 OutputString: 5a5b5c5d5e

The non-capturing regex 5. matches and replaces the same substrings as the capturing group (5.), but (5.) is used above to take advantage of the self-referring marker for the replacement string, $L1, which is valid only for capturing groups.

Products authorizing $RegexReplace