Sv RegexReplace
From GECK
A function added by the JIP NVSE Plugin.
Contents
Description
Returns a copy of the specified string_var, with all matches to the specified Regular Expression pattern replaced by the specified string.
The replacement and pattern are both passed as a single formatted string, separated by a |, i.e. replacement|pattern (see example, below).
Syntax
(modifiedSeq:string_var) sv_RegexReplace targetSeq:string_var replacement|pattern:formattedString formatVars(up to 20)
Example
let sTargetSeq := "This subject has a submarine as a subsequence" let sModifiedSeq := sv_RegexReplace sTargetSeq "blip!|\b(sub)([^ ]*)"
In the above example, every whole word in sTargetSeq that begins with the sequence "sub" is replaced by "blip!". The result sModifiedSeq is assigned the string "This blip! has a blip! as a blip!".
Notes
- Will crash the game if the Regex pattern is invalidly formatted. If it cannot be verified before the script runs, use ValidateRegex.
See Also
- Sv_Replace
- sv_RegexSearch
- sv_RegexMatch
- To test Regex expressions, consider using this website: Regex101