lua-users home
lua-l archive

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


On Mon, Oct 28, 2013 at 2:42 PM,  <meino.cramer@gmx.de> wrote:
> Hi,
>
> in the PIL 2ed I didn't find a way to search from the end of a string
> to the beginning. There is a way to specify an offset from the back
> with a negative instead of a positiv, but from that specified point
> the search goes from 'left to right' or 'front to back'.
> Is there real;y no equivalent to "RIGHTSTR()" in lua or did I overlook
> something ?
>
> Best regards,
> mcc

Lua pattern matching is from left-to-right with a flexible choice of
the starting position and special markers like ^ and $ for beginning
and end of a string. In most cases it is sufficient. If you *really*
need to match from right-to-left you can use string.reverse(s) and
apply reversed pattern to it. But in my experience, unless you are
doing something contrive, Lua's pattern matching rules are just fine.
Remember, you can use '$' to peg your pattern to the end-of-string.

--Leo--