Thanks for the idea, I'll write it down. Just one thing, could you explain the:
(?{print "$1\n"})(?!)
I don't understand the question mark before the print block. Also why the (?!) at the end. I noticed that removing it only prints ABC, but I don't understand why.
Thank you | [reply] [Watch: Dir/Any] [d/l] |
Short explanation: (?{...}) means to execute arbitrary Perl code inside a regular expression, and (?!) makes the regex engine to fail and backtrack, trying to match from the last_pos + 1. When it starts matching ABC, it prints it, fails, backtracks and starts matching from B the next three letters, giving us BCD. The process repeats until the internal regex counter reaches the end of the string.
I know, I'm really bad at explaining things to humans, but, fortunately, Athanasius explained this better once.
Please see: Re: RegEx + vs. {1,}
| [reply] [Watch: Dir/Any] [d/l] [select] |
Thanks a lot! Very well explained actually. It's a nice trick to know.
| [reply] [Watch: Dir/Any] |