On Sun, Feb 9, 2014 at 12:43 PM, Tonton San <lists / ruby-forum.com> wrote:
> I'm trying to evaluate an arithmetic operation of prefix type,
> "add(multiply(123,432),subtract(add(19,21),124))", can you make it so
> the regex engine scans it backwards?

Note Ruby's regexp engine since 1.9 can parse nested structures (i.e.
non regular languages but context free languages).  You'll find some
hints here
http://www.geocities.jp/kosako3/oniguruma/doc/RE.txt

> I'm trying to isolate each word and manipulate it without using split()
> and creating another array of o(n) space.
>
> I can parse the string from end to start by character and tokenize it
> using string index, but there must be someway to do this using regex
> efficiently.
>
> I know that split() creates an array that can be traversed backwards,
> but is there anyway to bypass the extra space required by split()? (Does
> the ruby interpreter/compiler somehow handle it?)
>
> Ultimately, is there anyway to make scan() parse a string backwards?

No.  You can reverse the String but then you also have to reverse the
regexp which is not trivial for all cases.

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/