youtuber Posted August 10, 2019 Share Posted August 10, 2019 Left and right part I want to not delete Left : "asdf":{"asdf_blabla":" Right : ","asdf_blabla" $s = '"asdf":{"asdf_blabla":"The part I want to replace","asdf_blabla"' Msgbox(0,"", StringRegExpReplace($s, '"asdf":{"asdf_blabla":"(.*?)","asdf_blabla"', 'add something to the part you want to change')) Link to comment Share on other sites More sharing options...
mikell Posted August 10, 2019 Share Posted August 10, 2019 Just use groups and backreferences Msgbox(0,"", StringRegExpReplace($s, '("asdf":{"asdf_blabla":")(.*?)(","asdf_blabla")', '$1add something to the part you want to change$3')) youtuber 1 Link to comment Share on other sites More sharing options...
youtuber Posted August 10, 2019 Author Share Posted August 10, 2019 (edited) @mikell Now I understand better $1 $2 $3 👍 Thank you Also I would like to add it from a variable but removing slash marks cause? $aDir = @ScriptDir & "\myfolder" $s = '"asdf":{"asdf_blabla":"The part I want to replace","asdf_blabla"' ConsoleWrite(StringRegExpReplace($s, '("asdf":{"asdf_blabla":")(.*?)(","asdf_blabla")', '$1' & $aDir & '$3') & @CRLF) "asdf":{"asdf_blabla":"C:UsersUSERDesktopmyfolder","asdf_blabla" Edited August 10, 2019 by youtuber Link to comment Share on other sites More sharing options...
mikell Posted August 10, 2019 Share Posted August 10, 2019 Yes, backslashes need to be escaped $aDir = @ScriptDir & "\myfolder" $aDir = StringReplace($aDir, "\", "\\") $s = '"asdf":{"asdf_blabla":"The part I want to replace","asdf_blabla"' ConsoleWrite(StringRegExpReplace($s, '("asdf":{"asdf_blabla":")(.*?)(","asdf_blabla")', '$1' & $aDir & '$3') & @CRLF) youtuber 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now