Here is my MWE:
\documentclass{article}
\RequirePackage{expl3}
\RequirePackage{xparse}
\ExplSyntaxOn
\newcounter{exercise}
\NewDocumentEnvironment{exercise}{}
{
\refstepcounter{exercise}
\par\noindent
\theexercise.\hspace{4pt}X
\ignorespaces
}
{
\par
\ignorespacesafterend
}
\ExplSyntaxOff
\begin{document}
\begin{exercise}
If $H$ is a subgroup of $G$, then something.
\end{exercise}
\begin{exercise}\label{A}
If $H$ is a subgroup of $G$, then something.
\end{exercise}
\end{document}
Note that there's extra space after the "X" in the second case. This appears to be caused by the \label
command. Of course, I'd like it to not be there, but I'm not sure where to begin with diagnosing the problem.