An Introduction to Regular Expressions The Split Operator 37 of 50 : [PREV] [NEXT]

Usage

Not commonly mentioned in the context of regular expressions, however the delimiter specifier can be a regular expression. In most instances split only splits on a single character. Consider the following statement:

split /,/, $line

This is expecting to read a Comma Separated Values file. However the following statement assumes the field separator can be either whitespace, a comma or colon and there is at least one character:

split /[\s,:]+/, $line

© 2003 Barbie barbie@missbarbell.co.uk Home http://birmingham.pm.org/