📜  正则表达式前瞻 - 无论代码示例

📅  最后修改于: 2022-03-11 14:59:14.760000             🧑  作者: Mango

代码示例2
# Can use a regex,so this Lookahead and Lookbehind ' to see that's there a word character on each end.

import re
import json
 
s = "[[('name', 'productname_0'), ('type', 'html'),('content', 'O'Cornor')],[('name', 'productname_1'), ('type', 'html'), ('content', 'Philp's')]]"
result =  re.sub(r"(?<=\w)\'(?=\w)", r"\\'", s)
print(result)
d = json.dumps(result)
print(json.loads(d))