Class StringSplitter


  • public class StringSplitter
    extends Object
    Provides a method for splitting a CharSequence using regex where both matching and non matching sub sequences are retained.
    • Constructor Detail

      • StringSplitter

        public StringSplitter​(String regex)
        Create a new StringSplitter using the supplied regex.
        Parameters:
        regex - the regular expression
    • Method Detail

      • split

        public static SplitResult[] split​(CharSequence input,
                                          Pattern pattern)
        Split the input string using the regular expression. Similar to the split method in the String class. However, contrary to split, all subsequences are returned, even the ones that match. In other words, the input can be reconstructed from the result.
        Parameters:
        input - the String to split
        pattern - the compiled regular expression
        Returns:
        returns an array of SplitResults that, if put together, contain all the characters from the input.
      • split

        public static SplitResult[] split​(CharSequence input,
                                          String regex)
        Split the input string using the regular expression. Similar to the split method in the String class. However, contrary to split, all subsequences are returned, even the ones that match. In other words, the input can be reconstructed from the result.
        Parameters:
        input - the String to split
        regex - the regular expression to use
        Returns:
        returns an array of SplitResults that, if put together, contain all the characters from the input.
      • split

        public SplitResult[] split​(CharSequence input)
        Split the input string using the regular expression. Similar to the split method in the String class. However, contrary to split, all subsequences are returned, even the ones that match. In other words, the input can be reconstructed from the result.
        Parameters:
        input - the String to split
        Returns:
        returns an array of SplitResults that, if put together, contain all the characters from the input.