The way I think it works is that the regex-engine starts by grabbing the whole of the string for the first capture and then sees that it cannot match anything anymore and thus starts "giving back" character by character to match the other elements of the regex.As 'x' has to come in blocks of 12 elements, the regex for that variable is (o*)\1{11}, being whatever the regex-engine in trying, followed by 11 times that what is being tried for the first capture. 11 + 1 = 12, so you have your '12x'. The same goes for the other variables. Probably inside the regex there are some shortcuts and optimizations, but basically it is just "try everything until you find a solution".
CountZero A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
| [reply] [Watch: Dir/Any] [d/l] |