in reply to regex needed for dot delimited string
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.$_ = '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]
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 |