My professor was showing us how to derive the ground state wavefunction for the quantum harmonic oscillator. He begins with the annihilation operator acting on the lowest energy eigenvector:
$$a|E_0\rangle = 0$$
Then he projects the equation onto the position eigenvector:
$$\langle x|a|E_0\rangle = 0$$
Here are the first couple steps:
\begin{align} \hat a | E_0 \rangle & =0 \\ \left(\frac{1}{b\sqrt{2}}\hat{x}+\frac{ih}{\hbar \sqrt{2}}\hat{p}\right)|E_0 \rangle & =0 \\ \langle x |\left(\frac{1}{b\sqrt{2}}\hat{x}+\frac{ih}{\hbar \sqrt{2}}\hat{p}\right)|E_0 \rangle & =0\\ \left(\frac{x}{b\sqrt{2}}+\frac{b}{\sqrt{2}}\frac{\mathrm d}{\mathrm d x}\right) \langle x|E_0\rangle &=0\\ \frac{x}{b\sqrt{2}}\psi_0(x)+\frac{b}{\sqrt{2}}\frac{\mathrm d \psi _0}{\mathrm d x}&=0 \end{align}
What I found confusing was the third line. He appears to be "pulling out" an operator which is sandwiched between a bra and a ket vector. I had initially thought that only constants (scalars) can be pulled out when sandwiched between a bra and a ket. I am poorly versed in Dirac notation and am clearly missing something. So my question is:
When are we allowed to "pull out" an operator sandwiched between a bra and a ket?