Regex lookahead example not as stated in Camel 4th
Abigail
abigail at abigail.be
Wed Jun 19 14:52:01 BST 2013
On Wed, Jun 19, 2013 at 02:36:14PM +0100, gvim wrote:
> 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
That's not a lookahead assertion. This is:
$ perl -wE 'say for "0123456789" =~ /(?=(\d{3}))/g'
012
123
234
345
456
567
678
789
$
Regards,
Abigail
More information about the london.pm
mailing list