http://www.perlmonks.org?node_id=1018775


in reply to Re^2: A regex that only matches at offset that are multiples of a given N?
in thread A regex that only matches at offset that are multiples of a given N?

Your second regex works,

I'm not seeing that:

use strict; use warnings; use 5.010; # 0 5 10 15 20 25 30 35 # ' ' ' ' ' ' ' ' $_ = q{....fred1....fred2...fred3....fred4..}; while (/fred(?(?{ pos % 4 != 0 })(?!))(....)/sg) { } --output:-- Use of uninitialized value in numeric ne (!=) at (re_eval 1) line 1. Use of uninitialized value in numeric ne (!=) at (re_eval 1) line 1. Use of uninitialized value in numeric ne (!=) at (re_eval 1) line 1.
  • Comment on Re^3: A regex that only matches at offset that are multiples of a given N?
  • Download Code

Replies are listed 'Best First'.
Re^4: A regex that only matches at offset that are multiples of a given N?
by smls (Friar) on Feb 14, 2013 at 21:16 UTC

    Ah yes, you need to add parenthesis after the pos (to make sure it is interpreted as a function without parameters):

    /fred(?(?{ pos() % 4 != 0 })(?!))(....)/sg

    I fixed that locally while testing ikegami's regex but then forgot about it when reporting back, sorry.