start_marker = end_marker = '$'
string = '$sin (x)$ is an function of x'
start = string.index(start_marker) + len(start_marker)
end = string.index(end_marker, start + 1)
string[start:end]
getting string between 2 characters in python