3
\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} 

Using this code I'm getting match & match group one after one.

Example

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

Output is enter image description here

Where First /1a1c6e99h6 is match & second half is match group 1a1c6e99h6

How can I only map match group 1a1c6e99h6

projetmbc
  • 13,315
  • Can you give us a compilable code? – projetmbc Feb 15 '23 at 08:28
  • Have you tried to pop the first element via \seq_pop_left before iterating on the sequence? The doc says : "If it exists, the match is stored as the first item of the ⟨seq var⟩, and further items are the contents of capturing groups, in the order of their opening parenthesis. " – projetmbc Feb 15 '23 at 08:32
  • That's the only code I'm using. Also \seq_pop_left is not working – d4rkshad0w Feb 15 '23 at 08:47
  • Gives us a code with \begin{document}... etc. This will allow us to copy and paste your code in https://texlive.net/run to quickly try something... – projetmbc Feb 15 '23 at 08:48
  • Added the code. – d4rkshad0w Feb 15 '23 at 08:54

2 Answers2

5

Here is how to pop left the sequence such as to obtain 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}

projetmbc
  • 13,315
3

I think you don't want extraction, but just replacement:

\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}

enter image description here

egreg
  • 1,121,712