From WikiChip
Editing mirc/identifiers/$regsubex

Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.

This page supports semantic in-text annotations (e.g. "[[Is specified as::World Heritage Site]]") to build structured and queryable content provided by Semantic MediaWiki. For a comprehensive description on how to use annotations or the #ask parser function, please have a look at the getting started, in-text annotation, or inline queries help pages.

Latest revision Your text
Line 3: Line 3:
 
'''Note''': All the matches are made before the replacements, the total number of matches as well as any capture of any match can be accessed in the replacement with {{mIRC|$regmlex}}
 
'''Note''': All the matches are made before the replacements, the total number of matches as well as any capture of any match can be accessed in the replacement with {{mIRC|$regmlex}}
  
'''Note2''': $regsubex returns the orignal input if there is no match found, if the /S modifier is used, the control code from the original input will not be returned.
+
'''Note2''': $regsubex returns the orignal input if there is no match found, if the /S modifier is used, the control code from the original input will be returned.
  
 
== Synopsis ==
 
== Synopsis ==
Line 25: Line 25:
 
== Example ==
 
== Example ==
 
<source lang="mIRC">//var %a | echo -a $regsubex(abcd,/([a-z])/g,-\n \1-)</source>
 
<source lang="mIRC">//var %a | echo -a $regsubex(abcd,/([a-z])/g,-\n \1-)</source>
 
Note how the 1st example below returns the string in red because the input is not altered when there were no matches. However because the 2nd example found at least 1 match, the result excludes any control codes stripped by the /S modifier flag.
 
 
<pre>
 
//echo -a $regsubex(foo,$chr(3) $+ 4test,/(z)/gS,x)
 
//echo -a $regsubex(foo,$chr(3) $+ 4test,/(.)/gS,x)</pre>
 
 
$regsubex does not return a numeric indicator of whether or not there was a match, it simply returns the input string altered by 0 or more matches, though it also does fill the named capture groups seen by $regml and $regmlex.
 
 
Example of translating hex strings into the base10 format needed by /bset
 
<pre>
 
//var -s %string $sha256(abc) , %pattern /([0-9a-fA-F]{2})\s*/g , %bytevals $regsubex(foo,%string,%pattern,$base(\t,16,10) $+ $chr(32)) | bset -c &binvar 1 %bytevals | echo -a $bvar(&binvar,1-)</pre>
 
 
Example of creating a list of the 94 text characters from codepoints 33-126. Note how this is only used for creating the \n token where it increments from the range 1-94, and since there were no capture groups the \t will always be null regardless if there were any matches, and the \t can be removed without changing the result:
 
 
<pre>//echo -a $regsubex(foo,$str(x,94),/x/g,\t $chr($calc(32+ \n)))</pre>
 
 
result: !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
 
 
Example of using $regsubex to create a series of 32 byte values. Then assuming there is 256 bits of entropy in the input, uses $regsubex to create a 256-bit key in hex format. Note that the 2nd method is probably preferrable since it allows each of the 32 random byte values to have an effect on each bit of the key, while the 1st method causes each byte value to affect only 8 bits of the key:
 
<pre>
 
//var -s %bytevals $regsubex(foo,$str(x,32),/x/g,$rands(0,255) $+ $chr(32)) | echo -a method1: $lower($regsubex(foo,%bytevals,/(\d+)\s*/g,$base(\t,10,16,2))) | echo -a method2: $sha256(%bytevals)</pre>
 
 
Example of ROT13 which replaces the a-m range + 13 as n-z, and replaces n-z with a-m. Also the english version of Atbash which replaces each alpha letter with the letter as if the alphabet was flipped backwards. Wizard was possibly created as a word originally due to being itself spelled backwards in this encoding.
 
 
<pre>
 
//echo -a $regsubex(maroon 123 FooBar,/([a-zA-Z])/g,$chr( $calc($asc(\t) $iif(\t isin abcdefghijklm,+13,-13) ))))
 
//echo -a $regsubex(maroon 456 Wizard,/([a-zA-Z])/g,$chr( $calc(91+64 + $and(32,$asc(\t)) - $asc($upper(\t)))))</pre>
 
 
results:
 
znebba 123 SbbOne
 
nzillm 456 Draziw
 
  
 
== Compatibility ==
 
== Compatibility ==
 
{{mIRC compatibility|6.17}}
 
{{mIRC compatibility|6.17}}
 +
 
== See Also ==
 
== See Also ==
 
* {{mIRC|$regml}}
 
* {{mIRC|$regml}}
* {{mIRC|$regmlex}}
 
 
* {{mIRC|$regsub}}
 
* {{mIRC|$regsub}}
 
* {{mIRC|$regex}}
 
* {{mIRC|$regex}}
* {{mIRC|$regerrstr}}
+
 
 +
[[Category:mIRC identifiers|regsubex]]

Please note that all contributions to WikiChip may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see WikiChip:Copyrights for details). Do not submit copyrighted work without permission!

Cancel | Editing help (opens in new window)