Forum: Ruby How backtracking works in Ruby?

Posted by Love U Ruby (my-ruby)
on 2013-01-18 17:01
Hi,


What i am going to ask is very basic thing I know. But,as a newbie to
this platform,I am not getting the keen concept of backtracking in Regex
of Ruby. In such a case can any one help me to understand the core of
this concept by answering the following questions?

(a) What is backtracking?

(b) Why we need it?(means how regex with backtracking differs from a
regex without backtracking?)

(c) How it works when it is being used with any Regex? (It would be
great if it can be visualized with some code snippets to understand how
does it work)

(d) In what situation we have to think of it to use?


I used the link( http://ruby-doc.org/core-1.9.3/Regexp.html ) to get
it's core,but my bad i am not getting the answers of all my above
questions from here to have the concept.


Thanks in advance!
Posted by Eric Christopherson (echristopherson)
on 2013-01-31 04:27
(Received via mailing list)
On Fri, Jan 18, 2013 at 10:01 AM, Arup Rakshit <lists@ruby-forum.com> 
wrote:
> (b) Why we need it?(means how regex with backtracking differs from a
> it's core,but my bad i am not getting the answers of all my above
> questions from here to have the concept.

This freely-available chapter from _Mastering regular expressions_
talks about backtracking, although it doesn't mention Ruby
specifically: http://oreilly.com/catalog/regex/chapter/ch04.html
Posted by Love U Ruby (my-ruby)
on 2013-01-31 20:05
Eric Christopherson wrote in post #1094478:
> On Fri, Jan 18, 2013 at 10:01 AM, Arup Rakshit <lists@ruby-forum.com>
> wrote:
>> (b) Why we need it?(means how regex with backtracking differs from a
>> it's core,but my bad i am not getting the answers of all my above
>> questions from here to have the concept.


Can anyone help me to understand the concept with some codes? Code 
examples always give us good visualization.

Thanks
Posted by Robert Klemme (robert_k78)
on 2013-02-01 08:53
(Received via mailing list)
On Thu, Jan 31, 2013 at 8:05 PM, Arup Rakshit <lists@ruby-forum.com> 
wrote:
> Eric Christopherson wrote in post #1094478:
>> On Fri, Jan 18, 2013 at 10:01 AM, Arup Rakshit <lists@ruby-forum.com>
>> wrote:
>>> (b) Why we need it?(means how regex with backtracking differs from a
>>> it's core,but my bad i am not getting the answers of all my above
>>> questions from here to have the concept.
>
>
> Can anyone help me to understand the concept with some codes? Code
> examples always give us good visualization.

Look into the regexp engines implementation.  You won't easily see how
the regexp engine works internally by only using it.  Better yet, get
a copy of "Mastering Regular Expressions" and digest it.

Cheers

robert
Posted by Art Taylor (Guest)
on 2013-02-01 20:47
(Received via mailing list)
On 1 Feb 2013, at 2:53 AM, Robert Klemme <shortcutter@googlemail.com> 
wrote:
>
> Look into the regexp engines implementation.  You won't easily see how
> the regexp engine works internally by only using it.  Better yet, get
> a copy of "Mastering Regular Expressions" and digest it.

This is very solid advice.  It's one of the references that you will use 
for years beyond Ruby.

-a.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.