expl3 – Latex3: why are spaces consumed before regex matches – TeX

I am trying to extract parts of a string using regular expressions.

For example, from a string input John Smith (role: proof reader) I would like to extract John Smith and proof reader.

Here’s my attempt

\ExplSyntaxOn

\seq_new:N \l_foo_seq

\regex_extract_once:nnN { ([\w\s]+)\(role:\s*([\w\s]+)\) } { {John Smith (role: proof reader)} } \l_foo_seq 

\newcommand{\showme}{
    \seq_map_inline:Nn \l_foo_seq {
        {##1,} \par
    }
}
\ExplSyntaxOff

The information I want is identified but the spaces are being removed. The output of \showme is

JohnSmith(role:proofreader),
JohnSmith,
proofreader,

I noticed that I can take the space-matching out of my regex and nothing changes, i.e.: ([\w]+)\(role:([\w]+)\). So, I guess the spaces are removed before \regex_extract_once:nnN does its stuff. I hoped that the enclosing braces would have presented the string as a single token with the spaces intact.

I’m a beginner at this. Advice and explanation would be welcome, as I’m finding the docs a bit hard to get into.

Read more here: Source link