I need to write a command that searches a file for a string that matches a certain regexp, and inserts that string. I know how to parse a string of text using a regex with
\usepackage{l3regex}
\ExplSyntaxOn
\cs_new_protected:Npn \mycom #1
{
\tl_set:Nn \l_tmpa_tl {#1}
\regex_replace_all:nnN { THE-REGEXP } { THE-REPLACEMENT } \l_tmpa_tl
\tl_use:N \l_tmpa_tl
}
\ExplSyntaxOff
but I don't know how I can use it to parse the contents of a file. I tried replacing {#1} with {\input{#1}}, but it didn't work (the \input was simply considered part of the string).
catchfilepackage 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). – Joseph Wright♦ Apr 25 '12 at 7:58