Find the index of the first digit in a string

前端 未结 14 899
清酒与你
清酒与你 2020-12-28 12:29

I have a string like

\"xdtwkeltjwlkejt7wthwk89lk\"

how can I get the index of the first digit in the string?

14条回答
  •  没有蜡笔的小新
    2020-12-28 12:48

    I'm sure there are multiple solutions, but using regular expressions you can do this:

    >>> import re
    >>> match = re.search("\d", "xdtwkeltjwlkejt7wthwk89lk")
    >>> match.start(0)
    15
    

提交回复
热议问题