获取手写文字识别括号内的值
如果是连续的字符可以用
re.findall(r'[(](.*?)[)]', result_word['content'])
不过如果是类似 括号不连续的情况下 应该如何获取结果
[{'confidence': 1, 'location': {'top_left': {'x': 847, 'y': 0}, 'right_bottom': {'x': 945, 'y': 20}}, 'word': [{'content': 'C.time'}]}, {'confidence': 1, 'location': {'top_left': {'x': 1, 'y': 0}, 'right_bottom': {'x': 464, 'y': 88}}, 'word': [{'content': '('}, {'content': 'A'}, {'content': ')'}, {'content': '2'}, {'content': '.'}, {'content': '-Lisa'}, {'content': ','}, {'content': 'you'}, {'content': '_'}, {'content': 'awful'}, {'content': '.'}]}, {'confidence': 1, 'location': {'top_left': {'x': 111, 'y': 85}, 'right_bottom': {'x': 464, 'y': 139}}, 'word': [{'content': '-I'}, {'content': 'know.'}, {'content': 'I'}, {'content': 'feel'}, {'content': 'awful,'}, {'content': 'too.'}]}, {'confidence': 1, 'location': {'top_left': {'x': 95, 'y': 155}, 'right_bottom': {'x': 209, 'y': 196}}, 'word': [{'content': 'A.look'}]}, {'confidence': 1, 'location': {'top_left': {'x': 479, 'y': 171}, 'right_bottom': {'x': 609, 'y': 210}}, 'word': [{'content': 'B.make'}]}, {'confidence': 1, 'location': {'top_left': {'x': 847, 'y': 178}, 'right_bottom': {'x': 960, 'y': 215}}, 'word': [{'content': 'C.looks'}]}, {'confidence': 1, 'location': {'top_left': {'x': 31, 'y': 200}, 'right_bottom': {'x': 65, 'y': 221}}, 'word': [{'content': 'D'}]}]
这个是我目前能获取连续字符括号内值的方法
for result_word in result_line['word']:
findall_1 = re.findall(r'[(](.*?)[)]', result_word['content'])
findall_2 = re.findall(r'[(](.*?)[)]', result_word['content'])
findall_3 = re.findall(r'[(](.*?)[)]', result_word['content'])
findall_4 = re.findall(r'[(](.*?)[)]', result_word['content'])
if(len(findall_1)!=0):
return findall_1[0]
elif(len(findall_2)!=0):
return findall_2[0]
elif(len(findall_3)!=0):
return findall_3[0]
elif(len(findall_4)!=0):
return findall_4[0]
这里有一个相同问题: 请查看是否对问题有帮助~
https://ask.csdn.net/questions/7732110
首先你这个中括号[]可以省去的呢
其次,你是想获取
这里边两个括号间的东西吗