如何从字符串中获取元素

时间:2012-06-01 07:33:35

标签: python-3.x

我想从字符串中获取特定内容,例如我有一个字符串:    硬件是FAS-2030-2T + 注意字符串开头的空格 我想要检索FAS-2030-2T + 我应该使用re.search还是re.match 如果是这样的话? 请帮助我,我被困在一些地方和新的python

提前致谢

-P

1 个答案:

答案 0 :(得分:0)

if(re.match('.*Hardware is.*',list)):
    #print ("Befroe List is ::",list)
    list1=shlex.split(list)
    #print ("List is ::",list1)
    print ("The Hardware is ::",list1[2])