Back from China, I’ve resume my normal programming schedule. I’m working through Pragmatic Bookshelf’s Programming Ruby, and there’s a lot more to ruby than I initially gave credit. For example, consider the following:
str = 'an' * 3000 + 'garbage' + 'an'*3000
r = /(?<pattern>.*) #The first part
(?:.*?) #Garbage
\k<pattern>/x #The first part, repeated.
str =~ r
puts $1.length
First, we create a repeated string, followed by some garbage data, followed by that string again. A pattern is built to find the largest prefix which is also a suffix, given a break in data. Ruby lets us name the regex