From 355b4d1dda5965ea9b58bd2c80e3703a55abce98 Mon Sep 17 00:00:00 2001 From: bculkin2442 Date: Fri, 10 Mar 2017 08:46:10 -0500 Subject: String manipulation additions More and better ways to manipulate strings --- .../java/bjc/utils/funcutils/NeoTokenSplitter.java | 112 +++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java (limited to 'BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java') diff --git a/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java new file mode 100644 index 0000000..fd4b130 --- /dev/null +++ b/BJC-Utils2/src/main/java/bjc/utils/funcutils/NeoTokenSplitter.java @@ -0,0 +1,112 @@ +package bjc.utils.funcutils; + +import java.util.regex.Pattern; + +/** + * Split a string and keep given delimiters. + * + * @author Ben Culkin + */ +public class NeoTokenSplitter { + /* + * This string is a format template for the delimiter matching regex + * + * It does two things + * 1. Match the provided delimiter by positive lookahead + * 2. Match the provided delimiter by positive lookbehind + * + * Thus, it will only match in places where the delimiter is, but won't + * actually match the delimiter, leaving split to put it into the stream + */ + private static String WITH_DELIM = "((?<=%1$s)|(?=%1$s))"; + + /* + * This string is a format template for the multi-delimiter matching + * regex. + * + * It does the same thing as the single delimiter regex, but has to have + * some negative lookahead/lookbehind assertions to avoid splitting a + * delimiter into pieces. + */ + private static String WITH_MULTI_DELIM = "((?<=%1$s+)(?!%1$s)|(?