forked from challenge-project/challenge-sandbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRegexFix.Script.txt
More file actions
47 lines (37 loc) · 1.22 KB
/
Copy pathRegexFix.Script.txt
File metadata and controls
47 lines (37 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
// RegexFix.Script.txt
// by BigBang1112
// part of Universe Library Set
// Fixes RegexReplace.
// This library does not depend on any other library from the Universe Library Set.
// You can use this library independently, although it's recommended to use the whole set.
*/
/*
// Compatible contexts:
// - CManiaApp
// - CMode
// - CServerPlugin
*/
#Include "TextLib" as TextLib
/*
// Text RegexReplace(Text _Pattern, Text _Text, Text _Flags, Text _Replacement)
// Regex replace with _Replacement supporting match insert. Define match group in replacement by \[number] with backslash properly escaped.
// Text _Pattern
// Text _Text
// Text _Flags
// Text _Replacement
// Returns _Text with replacements.
*/
Text RegexReplace(Text _Pattern, Text _Text, Text _Flags, Text _Replacement) {
declare Final = _Text;
declare MatchFlags = TextLib::Replace(_Flags,"g","");
declare Finds = TextLib::RegexFind(_Pattern, _Text, _Flags);
for(i,0,Finds.count-1) {
declare Matches = TextLib::RegexMatch(_Pattern, Finds[i], MatchFlags);
declare Replacement = _Replacement;
for(j,0,Matches.count-1)
Replacement = TextLib::Replace(Replacement, "\\"^j, Matches[j]);
Final = TextLib::Replace(Final, Finds[i], Replacement);
}
return Final;
}