HamidZaeri Posted September 16, 2018 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
mikell Posted September 16, 2018 Posted September 16, 2018 On 9/16/2018 at 10:27 AM, HamidZaeri said: it might be other number or text instead of zero Expand 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
HamidZaeri Posted September 16, 2018 Author Posted September 16, 2018 On 9/16/2018 at 11:15 AM, 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 Expand updated first post.
mikell Posted September 16, 2018 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)
HamidZaeri Posted September 16, 2018 Author Posted September 16, 2018 (edited) On 9/16/2018 at 3:59 PM, mikell said: Regex is not necessary for that $string = '"blah blah"}","answer":0,"authorization":"blah blah"' $new = StringReplace($string, "0", "none") Msgbox(0,"", $new) Expand َAs i said, it is not always 0 and might be other number or text Edited September 16, 2018 by HamidZaeri
iamtheky Posted September 16, 2018 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) Reveal hidden contents ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__)
mikell Posted September 16, 2018 Posted September 16, 2018 On 9/16/2018 at 6:44 PM, HamidZaeri said: As i said, it is not always 0 and might be other number or text Expand 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
HamidZaeri Posted September 17, 2018 Author Posted September 17, 2018 (edited) On 9/16/2018 at 8:03 PM, 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) Expand 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
mikell Posted September 17, 2018 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
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