|
@@ -620,7 +620,22 @@ procedure SplitRegExpr (const ARegExpr, AInputStr : RegExprString; APieces : TSt
|
|
|
// 'BLOCK( test1)', 'def "$1" value "$2"')
|
|
|
// will return: def "$1" value "$2"
|
|
|
function ReplaceRegExpr (const ARegExpr, AInputStr, AReplaceStr : RegExprString;
|
|
|
- AUseSubstitution : boolean{$IFDEF DefParam}= False{$ENDIF}) : RegExprString; //###0.947
|
|
|
+ AUseSubstitution : boolean{$IFDEF DefParam}= False{$ENDIF}) : RegExprString; overload; //###0.947
|
|
|
+
|
|
|
+// Alternate form allowing to set more parameters.
|
|
|
+
|
|
|
+Type
|
|
|
+ TRegexReplaceOption = (rroModifierI,
|
|
|
+ rroModifierR,
|
|
|
+ rroModifierS,
|
|
|
+ rroModifierG,
|
|
|
+ rroModifierM,
|
|
|
+ rroModifierX,
|
|
|
+ rroUseSubstitution,
|
|
|
+ rroUseOsLineEnd);
|
|
|
+ TRegexReplaceOptions = Set of TRegexReplaceOption;
|
|
|
+
|
|
|
+function ReplaceRegExpr (const ARegExpr, AInputStr, AReplaceStr : RegExprString; Options :TRegexReplaceOptions) : RegExprString; overload;
|
|
|
|
|
|
// Replace all metachars with its safe representation,
|
|
|
// for example 'abc$cd.(' converts into 'abc\$cd\.\('
|
|
@@ -726,7 +741,7 @@ end; { of procedure SplitRegExpr
|
|
|
--------------------------------------------------------------}
|
|
|
|
|
|
function ReplaceRegExpr (const ARegExpr, AInputStr, AReplaceStr : RegExprString;
|
|
|
- AUseSubstitution : boolean{$IFDEF DefParam}= False{$ENDIF}) : RegExprString;
|
|
|
+ AUseSubstitution : boolean{$IFDEF DefParam}= False{$ENDIF}) : RegExprString; overload;
|
|
|
begin
|
|
|
with TRegExpr.Create do
|
|
|
try
|
|
@@ -738,6 +753,27 @@ begin
|
|
|
end; { of function ReplaceRegExpr
|
|
|
--------------------------------------------------------------}
|
|
|
|
|
|
+function ReplaceRegExpr (const ARegExpr, AInputStr, AReplaceStr : RegExprString; Options :TRegexReplaceOptions) : RegExprString; overload;
|
|
|
+
|
|
|
+begin
|
|
|
+ with TRegExpr.Create do
|
|
|
+ try
|
|
|
+ ModifierI:=(rroModifierI in Options);
|
|
|
+ ModifierR:=(rroModifierR in Options);
|
|
|
+ ModifierS:=(rroModifierS in Options);
|
|
|
+ ModifierG:=(rroModifierG in Options);
|
|
|
+ ModifierM:=(rroModifierM in Options);
|
|
|
+ ModifierX:=(rroModifierX in Options);
|
|
|
+ // Set this after the above, if the regex contains modifiers, they will be applied.
|
|
|
+ Expression := ARegExpr;
|
|
|
+ UseOsLineEndOnReplace:=(rroUseOsLineEnd in Options);
|
|
|
+ Result := Replace (AInputStr, AReplaceStr, rroUseSubstitution in options);
|
|
|
+ finally
|
|
|
+ Free;
|
|
|
+ end;
|
|
|
+end;
|
|
|
+
|
|
|
+
|
|
|
function QuoteRegExprMetaChars (const AStr : RegExprString) : RegExprString;
|
|
|
const
|
|
|
RegExprMetaSet : RegExprString = '^$.[()|?+*'+EscChar+'{'
|