strreplace

Replaces a string, with another string.

Format

strreplace <strvar> <index> <regex> <newstr>

Remarks

Replaces a specified <regex> string in the string variable <strvar> beginning at a specified position <index>(1-origin), with another specified <newstr> string.
If the <newstr> is ''(empty), the <regex> string is removed from <strvar>.

Example

src='linux.txt'
strreplace src 1 '\.txt' '.doc'
messagebox src 'result'          ; linux.doc
src='I can do it.'
strreplace src 1 'can\s' ''
messagebox src 'result'     ; 'I do it.'
src='Microsoft Windows XP [Version 5.1.2600]'
strmatch src '(Version \d+.\d+.)\d+'

int2str s result
messagebox s groupmatchstr1
pos=result                ; 23
mstr=groupmatchstr1       ; Version 5.1.

strreplace src pos mstr 'Build '
if result=1 then
	messagebox src 'result'   ; Microsoft Windows XP [Build 2600]
endif

Reference

Oniguruma Regular Expressions
strmatch
strinsert
strremove