Skip to content
Advertisement

Replace string between two strings with duplicate markers in string

I using python and I have a multi-line string like this:

JavaScript

I want to replace "adamredsox24" in a large set of these types of strings with a variable (newName) but from set to set the substring will not always be "adamredsox24" at all and will be unknown to me. In other words, the substring in the quotes after the word White could be anything and I have no idea what it is but I want to replace it, how would I do that?

Also, the word white will always be there and the word I’m looking to replace will always be inside quotes beside the word White and the entire line will always be enclosed in [ ].

To see a sample of the data here is a code snippet:

JavaScript

I have tried things like:

JavaScript

And many variations of that with no luck. Here are a few more values for gameID to see more examples of the data: P2xKlpp6, is3qBnmQ, kEdXQOIw

Advertisement

Answer

I did some research in the API documentation and it appears the easiest way for you to reliably access the data you want is to get the data back in JSON.

Link to API Docs

Here is an example of the code that requests data in JSON format:

JavaScript

Getting the response in json allows you to easily access each part of the response by name and manipulate the data as you see fit.

Changing the player for the white chess piece

JavaScript

Json Response example

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement