I would like to define a command that counts the number of a substring in the input and apply corresponding operation according to the result.
For example, in the following code, the command should apply the corresponding rule according to the number of . in the input.
\documentclass{article}
\usepackage{xcolor}
\begin{document}
\ExplSyntaxOn
\cs_new:Nn \mymodule_apply_title_numbering_style_variant:n
{
\tl_set:Nx \l_tmpa_tl { #1 }
%% If #1 contains no '.'
\Huge\color{black}
%% If #1 contains one '.'
\large\color{black!80}
%% If #1 contains two '.'
\normalsize\color{black!60}
%% If #1 contains three '.'
\footnotesize\color{black!30}
\l_tmpa_tl
}
\mymodule_apply_title_numbering_style_variant:n { 1 }\par
\mymodule_apply_title_numbering_style_variant:n { 1.1 }\par
\mymodule_apply_title_numbering_style_variant:n { 1.1.1 }\par
\mymodule_apply_title_numbering_style_variant:n { 1.1.1.1 }
\end{document}
How can this be achieved?

titlesec? – Jasper Habicht May 23 '22 at 16:46\numberwithinand\numberwithoutto change the numbering level in the middle of the document, I cannot define the style to be a static one. Thus the question. – Jinwen May 23 '22 at 16:50