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

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)

 

  Reveal hidden contents

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

 

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