find the index of a pattern occurred in a string

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • RaZe
    New Member
    • Jul 2008
    • 3

    find the index of a pattern occurred in a string

    Hi,

    I am absolutely a beginner in Python. How can I find an index of a regular expression pattern if it matches within a string? For example a string: 'abc:def' and I want to get the index of ':' (colon) using the regular expression such as r'[^\w\s]. JAVA supports regular expression in the version of 'indexOf ()' function. How these could be done in Python?

    Thanks.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Use match object methods start() and end() to determine the starting and ending index numbers of the matched substring.

    Comment

    Working...