我有一个以下格式的字符串:
string = "x_abcd__A“
我想要得到两个"_“之间的值0
我尝试了string-3,但有时它的值可能是两个字符,例如x_abcd_10_A,它失败了。
我正在寻找一个语句,使用它我可以找到最后2个"_“之间的值。
发布于 2021-01-27 19:58:51
尝试以下操作:
import re
string = "x_abc_asdasd_asdasd_d__032_ds_asd__asd"
temp = re.match(r'([a-z_]*)(\d+)(\w*)', string).group(2)
print(temp) # print the extracted string
print(int(temp)) # convert extracted string into an int将生成以下输出:
032
32https://stackoverflow.com/questions/65918524
复制相似问题