I need to match from a a string \begin{?} and \end{?} where ? is any number of alphanumerical or * characters so it must match for example \begin{align} and \end{align*}.
I tried to do it but I’m not sure what’s wrong
^\\begin{[^}]*}$
Start with \begin{, following anything that's not } multiple times and close with }.
The same thing is with the \end{?} but I would like it do it inside single regex if possible.
I think below regex is what you need.
\\(begin|end){[a-zA-Z0-9*]+}