The limit parameter rules

The limit parameter controls the number of times the regular expression pattern is applied for splitting the subject string. It affects the length of the resulting array with the following rules:

  1. If the limit is greater than 0, then the pattern will be applied at most one time, the resulting array's length will not be greater than the limit, and the array's last entry will contain all input substrings beyond the last matched delimiter.
  2. If the limit is negative, then the pattern will be applied as many times as possible, and the resulting array can have any length.
  3. If the limit is zero (as in the single parameter split method call), then the pattern will be applied as many times as possible, the array can have any ...

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.