start() & end()<\/a><\/sub><\/p>\n\n\n\nThese expressions return the indices of the start<\/em> and end<\/em> of the substring matched by the group.<\/p>\n\n\n\nCode<\/strong><\/p>\n\n\n\n>>> import re\n>>> m = re.search(r'\\d+','1234')\n>>> m.end()\n4\n>>> m.start()\n0<\/code><\/pre>\n\n\n\n<\/span>Task<\/strong><\/span><\/h2>\n\n\n\nYou are given a string S<\/strong><\/em>.
Your task is to find the indices of the start<\/em> and end<\/em> of string k<\/em><\/strong> in S<\/em><\/strong>.<\/p>\n\n\n\n<\/span>Input Format<\/strong><\/span><\/h2>\n\n\n\nThe first line contains the string S<\/strong><\/em>.
The second line contains the string k<\/em><\/strong>.<\/p>\n\n\n\n<\/span>Constraints<\/strong><\/span><\/h2>\n\n\n\n- 0 < len<\/em>(S<\/em>) < 100<\/strong><\/li>
- 0 < len<\/em>(k<\/em>) < len<\/em>(S<\/em>)<\/strong><\/li><\/ul>\n\n\n\n
<\/span>Output Format<\/strong><\/span><\/h2>\n\n\n\nPrint the tuple in this format: (start<\/em> _index<\/em>, end<\/em> _index<\/em>).
If no match is found, print (-1, -1)<\/code>.<\/p>\n\n\n\nSample Input<\/strong><\/p>\n\n\n\naaadaa\naa<\/code><\/pre>\n\n\n\nSample Output<\/strong><\/p>\n\n\n\n(0, 1) \n(1, 2)\n(4, 5)<\/code><\/pre>\n\n\n\n<\/span>Solution – Re.start() & Re.end() in Python<\/strong><\/span><\/h2>\n\n\n\n# Enter your code here. Read input from STDIN. Print output to STDOUT\nimport re\n\nstring = input()\nsubstring = input()\n\npattern = re.compile(substring)\nmatch = pattern.search(string)\nif not match: print('(-1, -1)')\nwhile match:\n print('({0}, {1})'.format(match.start(), match.end() - 1))\n match = pattern.search(string, match.start() + 1)<\/pre>\n\n\n\n