Jump to content

help with regexp


HamidZaeri
 Share

Recommended Posts

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
Link to comment
Share on other sites

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

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)

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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