If as both your words and code imply, you are only after xxx and xxx always has length 3 then:
print substr($var,0,3);
is much simpler and faster than any regex.
If the length of xxx can vary then
print substr($var, 0, index($var, ':'));
is almost as simple and still more efficient that a regex. (And easier to get right first time:)
If you actually want to get xxx, yyy, and zzz and they are always length 3, then
my $p=0; print substr( $var, ($p=index($var, ':', $p+1 ))-3,3),$/ whil +e $p > -1
will won't quite (see below for reason and below that for correction. do the trick. Though it is a little harder to get right first time.
The use of a regex only really comes into its own when the number, and length of the entities to be matched can both vary is a lot more efficient for even the simple cases than I thought!
In reply to Re: split question
by BrowserUk
in thread split question
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |