in reply to regex needed for dot delimited string

$_ = '12d.9j7h.7tttt.125.ty.2.4.8.9f.y6.34gk.ll'; print "split: ", map "[$_]", grep $_, split /((?:\w+.){3}\w+)\.?/; print "regex: ", map "[$_]", m< ( (?: \w+. ){3} \w+ ) \.? >xg; __output___ split: [12d.9j7h.7tttt.125][ty.2.4.8][9f.y6.34gk.ll] regex: [12d.9j7h.7tttt.125][ty.2.4.8][9f.y6.34gk.ll]
Using split we use the capturing feature and grep out the extraneous data to get the desired output. With the regex we do something similar by capturing all the groups in the string. So it would seem, in this case the regex approach would be better.

See. perlre and split for more info.
HTH

_________
broquaint

update: fixed code (wasn't dealing with the last group correctly)

Replies are listed 'Best First'.
Re: Re: regex needed for dot delimited string
by zby (Vicar) on Sep 10, 2003 at 11:20 UTC
    The last character (an "l") in last group in both output strings is missing. (Are you sure you can use the dot in the regexp without escaping it?)