我有一个嵌入在json中的描述字段,我无法利用json库来解析这些数据。在
我使用{0,23}
来尝试提取字符串的前23个字符,如何提取与描述相关的整个值?在
import re
description = "'\description\" : \"this is a tesdt \n another test\" "
re.findall(r'description(?:\w+){0,23}', description, re.IGNORECASE)
对于上述代码,只显示['description']
Tags:
你可以试试这个代码:
结果是:
^{2}$基本上是:
这就是你在评论中要求的。在
解释-
(?<=description")
是一个积极的后视,它告诉正则表达式匹配description"
(?:\s*\:\s*)
是一个非捕获组,它告诉regexdescription"
后面将跟零个或多个空格、一个冒号(:
)和零个或多个空格。(".{0,23}?(?=")")
是实际需要的匹配,由双引号("
)、0到23个字符和结尾的双引号("
)组成。在相关问题 更多 >
编程相关推荐