import re class Solution: def reversePrefix(self, word: str, ch: str) -> str: match = re.search(rf"{ch}", word) if match: position = match.start() return word[: position + 1][::-1] + word[position + 1 :] else: return word