While writing in latex I often want to copy a math equation's right hand side or left hand side. For example I have something like this
\begin{gather*}
5 \cdot \left( A A 3 \right) + 50 \cdot \left( A A 3 \right) = 6CAB \\
500A + 50A + 15 + 5000A + 500A + 150 = 6000 + 100C + 10A + 5
\end{gather*}
and I'd like to copy the right and left hand side of the n-th last equation I've written and store them each in the l and r register respectively. For example if I were to use this on the 2nd last equation the l register would contain
5 \cdot \left( A A 3 \right) + 50 \cdot \left( A A 3 \right)
and the r register would contain
6CAB \\
So far I have this regex which represents a line that has an = between text
[^=]*\s\+=\s\+[^;]*
But I have no clue on how to somehow input what it's matching into registers and how to find the n-th last equation either... I was wondering if anyone could help me figure this out and was also wondering if this should be a macro?