Next: 1.7.3 Substituting Up: 1.7 Regular expressions Previous: 1.7.1 Matching Contents Index

## 1.7.2 Splitting

Sometimes it is desirable to split a string into pieces, such as when dealing with a comma-delimited file:

    `Jason Evans, jasone@canonware.com, http://www.canonware.com/~jasone/'

    `,\s*' split
    1 sprint

This generates the following output:

    [`Jason Evans' `jasone@canonware.com' `http://www.canonware.com/~jasone/']

If for some reason preserving the delimiters is important, capturing parentheses can be added to the splitting pattern:

    `Jason Evans, jasone@canonware.com, http://www.canonware.com/~jasone/'

    `(,)\s*' split
    1 sprint

This generates the following output:

    [`Jason Evans' `,' `jasone@canonware.com' `,' `http://www.canonware.com/~jasone/']