Consider the classic problem of a monkey hitting random keys on a keyboard, each with equal probability, and calculating the expected time for the monkey to type $\texttt{ABRACADABRA}$ (if unfamiliar with the martingale solution see, e.g., this question).
Is there a straightforward way to extend the solution to an arbitrary alphabet, arbitrary distribution of hitting the keys on the alphabet, and arbitrary string?
Edit
Based on Misha Lavrov's and user6247850's answers and comments. Let $A$ be an alphabet, $p$ be a probability distribution over the characters of this alphabet and $S$ be a string, with $s_i$ the $i$-th character. Let $p(s_i)$ be the probability of hitting this character.
I define $L_n(S)$ the left substring of $S$ of length $n$ by the first $n$ characters of $S$, and analogously $R_n(S)$ the right substring of $S$ of length $n$ by the last $n$ characters of $S$.
The expectation of the stopping time $T_S$ will be:
$$\mathbb{E}(T_S) = \sum_{i=1}^{\#S}\left(\prod_{j=1}^i p(s_j)^{-1}\right)\mathbf{1}(R_i(S) = L_i(S)),$$
where $\mathbf{1}$ denotes the indicator function. Is this correct?
The generalization to arbitrary alphabet and arbitrary string does not take much additional work. For an alphabet of size $k$ and an arbitrary string $s_1 s_2 \dots s_t$:
The bets are all fair (expected value $0$). After $N$ keystrokes, there are $N$ gamblers, who start with $\$N$ total, so the expected amount they end with is also $\$N$. This remains the same in expectation if $N$ is a stopping time, such as the time when the string $s_1s_2 \dots s_t$ first appears.
At this stopping time, one lucky gambler has won $\$k^t$. Also, for all $0<i<t$, if the string's first $i$ letters are equal to its last $i$ letters (if $s_1 s_2 \dots s_i = s_{t-i+1} s_{t-i+2} \dots s_t$) then another gambler has won $\$k^i$. This tells us the total amount of money anyone has at time $N$, so it must also tell us the expected value of time $N$.
Some special cases:
To generalize to arbitrary probabilities, we need to adjust the payoffs to make the game fair. Suppose that the string is still $s_1 s_2 \dots s_t$, but now letter $s_i$ has probability $p_i$ of occurring. Betting on a letter with probability $p$ should get a gambler $\frac1p$ dollars for every dollar they bet. Therefore the final gambler's winnings are $(p_1 p_2 \dotsm p_t)^{-1}$, and for every overlap $s_1 s_2 \dots s_i = s_{t-i+1} s_{t-i+2} \dots s_t$, there is another gambler with winnings $(p_1 p_2 \dotsm p_i)^{-1}$. The sum of these is the expected time until the string appears.