Jump to content

Recommended Posts

Posted (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 by HamidZaeri
Add expected result
Posted
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

Posted
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.

Posted (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 by HamidZaeri
Posted

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)

 

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Posted
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)

 

Posted (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 by HamidZaeri

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...