HamidZaeri Posted September 16, 2018 Share Posted September 16, 2018 (edited) Hi How can I use StringRegExpReplace to replace the zero number in below string with some other number? "blah blah"}","answer":0,"authorization":"blah blah" ----> "blah blah"}","answer":none,"authorization":"blah blah" and it might be other number or text instead of zero Edited September 16, 2018 by HamidZaeri Add expected result Link to comment Share on other sites More sharing options...
mikell Posted September 16, 2018 Share Posted September 16, 2018 44 minutes ago, HamidZaeri said: it might be other number or text instead of zero More details needed. What about the whole initial string, the parts to be replaced, the expected results ? Please provide a precise example so we can work with Link to comment Share on other sites More sharing options...
HamidZaeri Posted September 16, 2018 Author Share Posted September 16, 2018 Just now, mikell said: More details needed. What about the whole initial string, the parts to be replaced, the expected results ? Please provide a precise example so we can work with updated first post. Link to comment Share on other sites More sharing options...
mikell Posted September 16, 2018 Share Posted September 16, 2018 Regex is not necessary for that $string = '"blah blah"}","answer":0,"authorization":"blah blah"' $new = StringReplace($string, "0", "none") Msgbox(0,"", $new) Link to comment Share on other sites More sharing options...
HamidZaeri Posted September 16, 2018 Author Share Posted September 16, 2018 (edited) 1 hour ago, mikell said: Regex is not necessary for that $string = '"blah blah"}","answer":0,"authorization":"blah blah"' $new = StringReplace($string, "0", "none") Msgbox(0,"", $new) َAs i said, it is not always 0 and might be other number or text Edited September 16, 2018 by HamidZaeri Link to comment Share on other sites More sharing options...
iamtheky Posted September 16, 2018 Share Posted September 16, 2018 you can still stringop it $string = '"blah blah"}","answer":zer0,"authorization":"blah blah"' $replace = stringreplace($string , stringmid($string , stringinstr($string , '"answer":') + stringlen('"answer":') , stringinstr($string , ',"authorization":') - stringinstr($string , '"answer":') - stringlen('"answer":')) , "REPLACEMENT") msgbox(0, '' , $replace) ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted September 16, 2018 Share Posted September 16, 2018 1 hour ago, HamidZaeri said: As i said, it is not always 0 and might be other number or text Exactly the reason why I asked for more details. How do you think a regex can be built without knowing ALL the requirements ? "It might be other number or text" is not precise enough. The part to be replaced must be precisely defined : format, location, etc Example using location : $string = '"blah blah"}","answer":0,"authorization":"blah blah"' $new = StringRegExpReplace($string, '(?<=answer":)([^,]*)', "none") Msgbox(0,"", $new) HamidZaeri 1 Link to comment Share on other sites More sharing options...
HamidZaeri Posted September 17, 2018 Author Share Posted September 17, 2018 (edited) 8 hours ago, mikell said: Exactly the reason why I asked for more details. How do you think a regex can be built without knowing ALL the requirements ? "It might be other number or text" is not precise enough. The part to be replaced must be precisely defined : format, location, etc Example using location : $string = '"blah blah"}","answer":0,"authorization":"blah blah"' $new = StringRegExpReplace($string, '(?<=answer":)([^,]*)', "none") Msgbox(0,"", $new) I need to know how to use regexp to find a dynamic text between two static texts. "Dynamic1" & "Static1" & "Dynamic2" & "Static2" & "Dynamic3" How to replace Dynamic2 with regexp? (Static1 and Static2 are not repeated in other texts) Edited September 17, 2018 by HamidZaeri Link to comment Share on other sites More sharing options...
mikell Posted September 17, 2018 Share Posted September 17, 2018 Ha, this requirement is much more explicit Finding anything between two static texts is exactly what _StringBetween (which uses regex internally) is made for 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