lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



----- Original Message -----
> On Fri, Apr 13, 2012 at 4:07 PM, Robert Virding
> <robert.virding@erlang-solutions.com> wrote:
> > But isn't that what %0 is for.
> 
> Yes, but %0 is only available for string replacements. %1 is
> synthesized to be the entire match for all types of replacements, as
> this is convenient for all non-string replacements.

I don't doubt you but I can't read that out of what it says in the manual:

"If repl is a string, then its value is used for replacement. The character % works as an escape character: any sequence in repl of the form %d, with d between 1 and 9, stands for the value of the d-th captured substring (see below). The sequence %0 stands for the whole match. The sequence %% stands for a single %.

If repl is a table, then the table is queried for every match, using the first capture as the key; if the pattern specifies no captures, then the whole match is used as the key.

If repl is a function, then this function is called every time a match occurs, with all captured substrings passed as arguments, in order; if the pattern specifies no captures, then the whole match is passed as a sole argument."

There is no problem implementing it this way. I will have to do some more checking with using tables and functions.