Difference between revisions of "ScriptCore3.ReplaceRegExpr"

From Soldat Community Wiki
Jump to: navigation, search
(Examples)
Line 13: Line 13:
  
 
==Examples==
 
==Examples==
Escape regular expression special characters like "$" by excluding all the non-alpha numerical characters in
+
Escaping regular expression special characters like "$" by excluding all the non-alpha numerical characters and underscore.
 
<pre>
 
<pre>
 
ReplaceRegExpr('[^a-zA-Z0-9_]','a!b$c@defgh','\\$&',True);
 
ReplaceRegExpr('[^a-zA-Z0-9_]','a!b$c@defgh','\\$&',True);
Line 19: Line 19:
 
a\!b\$c\@def\$gh
 
a\!b\$c\@def\$gh
 
</pre>
 
</pre>
 +
  
 
<pre>
 
<pre>

Revision as of 20:19, 20 September 2018

function ReplaceRegExpr(const ARegExpr, AInputStr, AReplaceStr: string; AUseSubstitution: boolean): string
 ARegExpr: regular expression
 AInputStr: string to be altered
 AReplaceStr: replacement for occurencies of ARegExpr
 AUseSubstitution: if TRUE, AReplaceStr will be used as template of the result

Description

Returns AInputStr with r.e. occurencies replaced by AReplaceStr.

If AUseSubstitution is true, then AReplaceStr will be used as template for Result.

For detailed information about Regular Expressions see Regular_Expression on Wikipedia

Examples

Escaping regular expression special characters like "$" by excluding all the non-alpha numerical characters and underscore.

ReplaceRegExpr('[^a-zA-Z0-9_]','a!b$c@defgh','\\$&',True);
-->
a\!b\$c\@def\$gh


ReplaceRegExpr('1','asd1ffg1sa','ONE',FALSE)
-->
asdONEffgONEsa
ReplaceRegExpr('({-i}block|var)\s*\(\s*([^ ]*)\s*\)\s*','BLOCK( test1)', 'def "$1" value "$2"', True)
-->
def 'BLOCK' value 'test1'
ReplaceRegExpr('({-i}block|var)\s*\(\s*([^ ]*)\s*\)\s*','BLOCK( test1)', 'def "$1" value "$2"', False)
-->
def "$1" value "$2"