0 out of 464 challenges solved
Write a Python function `find_literals` that searches a given string for a specified regex pattern. The function should return a tuple containing the matching substring, the start index, and the end index of the match. #### Function Signature ```python [main.nopy] def find_literals(text: str, pattern: str) -> tuple: pass ``` #### Input - `text` (str): The string to search within. - `pattern` (str): The regex pattern to search for. #### Output - A tuple `(match, start_index, end_index)` where: - `match` is the substring that matches the pattern. - `start_index` is the starting index of the match. - `end_index` is the ending index of the match. #### Example Usage ```python [main.nopy] find_literals('The quick brown fox jumps over the lazy dog.', 'fox') # Output: ('fox', 16, 19) find_literals('Its been a very crazy procedure right', 'crazy') # Output: ('crazy', 16, 21) find_literals('Hardest choices required strongest will', 'will') # Output: ('will', 35, 39) ``` #### Notes - If no match is found, the function should return `None`. - Use the `re` module for regex operations.
import re def find_literals(text: str, pattern: str) -> tuple: """ Searches for a regex pattern in a given string and returns the match details. Args: text (str): The string to search within. pattern (str): The regex pattern to search for. Returns: tuple: A tuple containing the matching substring, start index, and end index. """ # Implement the function logic here pass