我有这样一个字符串:Test Step 01-08-04 U upper 100 m/s
目前我使用:
self.current_xtp_test_case = re.findall("\d+", test_case.attrib["name"])
self.current_xtp_test_case = ''.join(map(str,self.current_xtp_test_case[-1:]))
self.current_xtp_test_case = self.current_xtp_test_case.lstrip("0")
上面的代码应该得到00-00-00模式中的最后一个数字,它最终应该是4
,因为我需要删除0
。但是现在对于我正在处理的数据,有时可能会有一个除00-00-00
之外的数字,就像上面的例子一样,我在字符串的末尾有100,这会弄乱我当前代码的逻辑。你知道吗
如何更改代码以便只能选择模式01-03-04中的最后一个数字-我只想选择04
部分。希望这有意义?你知道吗
据我所知,这个问题看起来就是你要问的
import re string_to_parse = "Test Step 01-08-04 U upper 100 m/s" find_result = re.findall('\d+-\d+-\d+', my_string)[0] print(find_result[-1])
;您可以这样做:
输出:
希望对您有所帮助;)
相关问题 更多 >
编程相关推荐