import re def find_letter_index(string): pattern = r'([a-zA-Z])x\b' matches = re.findall(pattern, string) letter_indices = [] for match in matches: letter_index = string.index(match) letter_indices.append(letter_index) return letter_indices # 示例使用 string = "ax+b + cx - dx + e^x" indices = find_letter_index(string) print(indices)