本文介绍了如何从字符串中提取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
从字符串中提取字符串
string ='[{roll:context(345)},{roll:context(344 ))}]'
预期输出,
['roll',context(345),'roll',context (345)]
我尝试过:
import re
re.findall(r ' ([^] *)',string)
当前输出,[' roll',' 345',' roll',' 344']
预期输出,
[' roll',context( 345),' roll',context( 345)]
解决方案
extract strings from a string
string = '[ {"roll" : context("345") }, {"roll" : context("344")) } ]'
Expected output,
['roll', context("345"), 'roll', context("345")]
What I have tried:
import re re.findall(r'"([^"]*)"', string) Present Output, ['roll', '345', 'roll', '344'] Expected output, ['roll', context("345"), 'roll', context("345")]
解决方案
这篇关于如何从字符串中提取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!