However, if you want to have \tl_set_rescan:Nnn use the catcode setting in #2 in force when grabbing the token list to retokenize, as you said in the comments, you can write a simple wrapper around \tl_set_rescan:Nnn to have it use that catcode setting. As an example, I defined a wrapper which works somewhat like \verb, in the sense that if the next token is a {, the argument is delimited by the next (balanced) }, and if it is something else, the argument is delimited by the next something else:
\documentclass{article} \usepackage{expl3} \ExplSyntaxOn \cs_new_protected:Npn \siracusa_dynamic_tl_set_rescan:Nnn #1#2 { \group_begin: \peek_catcode:NTF \c_group_begin_token { \__dynamic_tl_rescan_brace:Nnn #1 {#2} } { \__dynamic_tl_rescan_delim:Nnw #1 {#2} } } \cs_new_protected:Npn \__dynamic_tl_rescan_brace:Nnn #1 #2 { #2 \__dynamic_tl_rescan_do:Nnn #1 {#2} } \cs_new_protected:Npn \__dynamic_tl_rescan_delim:Nnw #1 #2 #3 { \cs_set:Npn \__siracusa_tmp:w ##1 ##2 ##3 #3 { \__dynamic_tl_rescan_do:Nnn ##1 {##2} {##3} } #2 \__siracusa_tmp:w #1 {#2} } \cs_new_protected:Npn \__dynamic_tl_rescan_do:Nnn #1 #2 #3 { \group_end: \tl_set_rescan:Nnn #1 {#2} {#3} } \ExplSyntaxOff \begin{document} \ExplSyntaxOn \group_begin: \char_set_catcode_escape:N \~ ~char_set_catcode_letter:N ~\ ~char_set_catcode_space:n {32} ~tl_set:Nn ~l_tmpa_tl {<\verb|\LaTeX| \LaTeX>} ~tl_analysis_show:N ~l_tmpa_tl ~group_end: %%%%%%%%%% \siracusa_dynamic_tl_set_rescan:Nnn \l_tmpa_tl { \char_set_catcode_space:n {32} \char_set_catcode_letter:N \\ } {<\verb|\LaTeX| \LaTeX>} \tl_analysis_show:N \l_tmpa_tl \ExplSyntaxOff \end{document} With this code, both token lists are:
> < (the character <) > \ (the letter \) > v (the letter v) > e (the letter e) > r (the letter r) > b (the letter b) > | (the character |) > \ (the letter \) > L (the letter L) > a (the letter a) > T (the letter T) > e (the letter e) > X (the letter X) > | (the character |) > (blank space ) > \ (the letter \) > L (the letter L) > a (the letter a) > T (the letter T) > e (the letter e) > X (the letter X) > > (the character >)