You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
19 lines
380 B
19 lines
380 B
11 months ago
|
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)
|