[Chicago-talk] REGEX question

Steven Lembark lembark at wrkhors.com
Fri Apr 16 22:58:16 CDT 2004

Assign the result of globally applying a regex
to the buffer and you'll get everything that
maches in one pass:

	my $regex = /(whatever)(matches)/;

	my @result = $buffer =~ /$regex/g;

You can also use a while loop with \Z to match
where the last regex left off.

One nice trick with split is that it can capture
what was used to split on (nice if the separator
varies between runs or within the buffer):

	my @stuff = split /(\W+)/, $buffer;

will split the buffer on non-word char's and
save both the matched portion from the regex
and the split-out pieces between.

Steven Lembark
Workhorse Computing
+1 888 359 3508

More information about the Chicago-talk mailing list