若可以 import json 的話...
import json
str = "{'id'='XX','ad'='xxxx'}".replace('=',':').replace("'","\"")
jsonobj = json.loads(str)
print(jsonobj['ad'])
正規表示式(Regular Expression)
https://en.wikipedia.org/wiki/Regular_expression
找python用的
http://python-learnnotebook.blogspot.com/2018/10/python-regular-expression.html
https://docs.python.org/3/library/re.html
你可用線上工具去測試出你需要的正規表示式的語法
https://www.debuggex.com/
如同邦友說的使用Regular Expression的作法
import re
example = r"{'id'='XX','ad'='xxxx'}"
pattern = r"(?<='ad'=').*(?=')"
result = re.search(pattern, example)
print(result.group(0))