I want to store some regex string in a json file, then use python to parse json file. however, as the regex backslash will be treated as invalid in json. so How should I do.
{
"key" : "^https://www\.google\.com/search?.+",
"value" : "google"
}
As you can see above, As regular expression, some fullstop (?.+) will be regex, some will be just fullstop (.), however, this json file will not be thought as valid. So how should I do.
Thanks!
解决方案
Add one more back slash for each and every back slash .
str=str.replace("\", "\\");
add above code into code before json usage..!
{
"key": "^https://www\\.google\\.com/search?.+",
"value": "google"
}
Its valid one..!
HOpe it helps...!
1313

被折叠的 条评论
为什么被折叠?



