There is no facility, at the moment, for storing into a token list the contents of a file, but you can still use the catchfile
package:
\documentclass{article}
\usepackage{catchfile}
\usepackage{expl3,l3regex}
\ExplSyntaxOn
\cs_new_protected:Npn \mycom #1
{
\CatchFileDef \l_tmpa_tl {#1} {}
\regex_replace_all:nnN { xrep } { foo } \l_tmpa_tl
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff
\mycom{xrep}
Update
In the revision dated 2014-06-25, the functionality has been added to expl3
:
\documentclass{article}
\usepackage{expl3,l3regex,xparse}
\ExplSyntaxOn
\NewDocumentCommand{\mycom}{m}
{
\malabarba_mycom:n { #1 }
}
\tl_new:N \l_malabarba_mycom_content_tl
\cs_new_protected:Npn \malabarba_mycom:n #1
{
\tl_set_from_file:Nnn \l_malabarba_mycom_content_tl {} {#1}
\regex_replace_all:nnN { xrep } { foo } \l_malabarba_mycom_content_tl
\tl_use:N \l_malabarba_mycom_content_tl
}
\ExplSyntaxOff
\mycom{xrep}
Note that there's a difference between \CatchFileDef
and \tl_set_from_file:Nnn
: in the former command the trailing argument contains setup instructions to be performed (locally) before loading the file, in the latter these setup tokens should go in the second argument
\CatchFileDef<command name>{<filename>}{<setup>}
\tl_set_from_file:Nnn <tl variable> { <setup> } { <filename> }
The analog of \CatchFileEdef
is called
\tl_set_from_file_x:Nnn
catchfile
package to allow you to read an entire file to a macro, or iterate over the file line-by-line with\ior_map_inline:Nn
(experimental function).