lua-users home
lua-l archive

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


On Jan 23, 2008 10:31 AM, Jeff Wise <jwise@sealyrealty.com> wrote:
> The "^[\f]*[\f]+$" is supposed to capture any/all up to a FormFeed (x'0c').
> I am capturing nothing.  What have I done wrong?

Your pattern says 'zero or more form feeds followed by a form feed'. I think meant to say 'zero or more NON-form feed characters, followed by a form feed', which would be "[^\f]*\f".

You are also anchoring the pattern to the beginning and end of the string. Since you have the entire file in a single string, this will only work if the entire file is a single page and the last character is a form feed.

To grab \f delimited pages from a buffer, you don't need the anchors:

   local pages = {}
   for page in data:gmatch('[^\f]*\f+') do
     pages[ #pages + 1 ] = page
   end

If you want to capture only the text (discarding the form feeds), change the _expression_ to '([^\f]*)\f+', which will 'capture' the part you want.

Cheers,
Eric