查找字符串中第一个数字的索引
发布于 2021-01-29 15:15:07
我有一个像
"xdtwkeltjwlkejt7wthwk89lk"
如何获取字符串中第一位的索引?
关注者
0
被浏览
142
1 个回答
-
用途
re.search()
:>>> import re >>> s1 = "thishasadigit4here" >>> m = re.search(r"\d", s1) >>> if m is not None: ... print("Digit found at position", m.start()) ... else: ... print("No digit in that string") ... Digit found at position 13