in reply to Pattern Matching with REGEXP: Is the match position trackable?

belg4mit's regex (++) is much cleaner than the one I wrote, so I won't post mine ;)

However, since you wanted the position of the _first_ 5, I'd substitute @- (also known as @LAST_MATCH_START) for pos.

# following line stolen shamelessly from belg4mit's post while( /(?<=H)5+(?=H)/g ){ print $-[0]; }

Oh yeah, FYI @LAST_MATCH_START starts counting at zero, not one.

Replies are listed 'Best First'.
Re: Re: Pattern Matching with REGEXP: Is the match position trackable?
by belg4mit (Prior) on Sep 18, 2002 at 13:48 UTC
    One could also trap the 5+ and subtract the length from pos, esp. if worried about compatability as this is rather new (5.6) IIRC.

    --
    perl -pew "s/\b;([mnst])/'$1/g"

      First of all, thank you all very much for replying to my problem. I will start going through all of your suggestions/fixes and come back later today :)