如何从 LaTex 正则表达式匹配中获取组?

如何从 LaTex 正则表达式匹配中获取组?
\documentclass{article}

\usepackage{hyperref}
\usepackage{expl3}


\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=cyan,
    pdftitle={Overleaf Example},
    pdfpagemode=FullScreen,
}

\ExplSyntaxOn
\NewDocumentCommand{\curl}{m}{
    \tl_set:Nn \l_tmpa_tl {#1}
    \regex_extract_once:nnN  {\/([a-z0-9]{10})}  {#1} \l_uiy_result_seq
    \seq_map_inline:Nn \l_uiy_result_seq {\href{#1}{##1}}
}
\ExplSyntaxOff


\begin{document} 

\curl{https://www.facebook.com/reel/1a1c6e99h60a3169h86816}

\end{document} 

使用此代码我得到一个接一个的匹配和匹配组。

例子

\curl{https://www.facebook.com/reel/1a1c6e99h60a3169h86816}

输出为 在此处输入图片描述

其中第一场/1a1c6e99h6是比赛,第二场是比赛组1a1c6e99h6

我如何才能仅映射匹配组1a1c6e99h6

答案1

以下是如何弹出左侧序列以获取1a1c6e99h6

\documentclass{article}

\usepackage{hyperref}
\usepackage{expl3}

\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=cyan,
    pdftitle={Overleaf Example},
    pdfpagemode=FullScreen,
}

\ExplSyntaxOn
\NewDocumentCommand{\curl}{m}{
    \regex_extract_once:nnN  {\/([a-z0-9]{10})}  {#1} \l_uiy_result_seq

    % One good example of use of l_tmpa_tl.
    \seq_pop_left:NNTF \l_uiy_result_seq \l_tmpa_tl {
        \seq_map_inline:Nn \l_uiy_result_seq {\href{#1}{##1}}
    }{
        No ~ match!
    }
}
\ExplSyntaxOff


\begin{document} 

\curl{https://www.facebook.com/reel/1a1c6e99h60a3169h86816}

\curl{PB}

\end{document} 

答案2

我认为您不想提取,而只是替换:

\documentclass{article}

\usepackage{hyperref}
\usepackage{expl3}


\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=cyan,
    pdftitle={Overleaf Example},
    pdfpagemode=FullScreen,
}

\ExplSyntaxOn

\NewDocumentCommand{\curl}{m}
  {
    \tl_set:Nn \l_tmpa_tl {#1}
    \regex_replace_once:nnN  {.*\/([a-z0-9]{10}).*} {\1} \l_tmpa_tl
    \href{#1}{\l_tmpa_tl}
  }
\ExplSyntaxOff


\begin{document} 

\curl{https://www.facebook.com/reel/1a1c6e99h60a3169h86816}

\end{document} 

在此处输入图片描述

相关内容