我有一个类似
的字符串"xdtwkeltjwlkejt7wthwk89lk"
如何获取字符串中第一个数字的索引?
最佳答案
使用 re.search()
:
>>> import re
>>> s1 = "thishasadigit4here"
>>> m = re.search(r"\d", s1)
>>> if m:
... print("Digit found at position", m.start())
... else:
... print("No digit in that string")
...
Digit found at position 13
关于python - 查找字符串中第一个数字的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4510709/