Regex lookahead example not as stated in Camel 4th

gvim gvimrc at gmail.com
Wed Jun 19 14:36:14 BST 2013


The 4th edition of the Camel states:

*****************************
"0123456789" =~ /(\d{3})/g

returns only three strings: 012, 345, and 678. By wrapping the capture 
group with a lookahead assertion:

"0123456789" =~ /(?:(\d{3}))/g

you now retrieve all of 012, 123, 234, 345, 456, 567, 678, and 789.

******************************

Howevery, my test with perl 5.14.2 on Ubuntu 13.04 does not concur:

$ perl -E 'say for "0123456789" =~ /(\d{3})/g'
012
345
678

$ perl -E 'say for "0123456789" =~ /(?:(\d{3}))/g'
012
345
678

gvim




More information about the london.pm mailing list