public static String splitString(final String s) { try { // ErrorDump.log(this, s); StringBuffer regexp = new StringBuffer(); String finalResult = s; String tokens[] = generateTokens(s); java.util.List<String> regexps = new LinkedList<String>(); for (String token : tokens) { String processedToken = processToken(token); if (processedToken != null) { if (mixedToken(token, processedToken)) processedToken = ".*"; finalResult = finalResult.replace(token, processedToken); regexps.add(processedToken); regexp.append(processedToken); } } return deSimplifyToken(finalResult); } catch (Exception e) { ErrorDump.error(SmartString.class, e); return s; } }
public static void main(String[] args) { ErrorDump.debug(SmartString.class, splitString("mozilla.12.7")); ErrorDump.debug(SmartString.class, splitString("heya[*]")); ErrorDump.debug(SmartString.class, splitString("123-453-23")); ErrorDump.debug(SmartString.class, splitString("Tel # 123-453-23")); ErrorDump.debug(SmartString.class, splitString("Telephone nr. 123-453-23")); ErrorDump.debug(SmartString.class, splitString("Szinek, PETER")); ErrorDump.debug(SmartString.class, splitString("BAUMGARTNER, Robert")); ErrorDump.debug(SmartString.class, splitString("Dr. Georg Gottlob")); ErrorDump.debug(SmartString.class, splitString("THE WASHINGTON POST")); ErrorDump.debug(SmartString.class, splitString("There were 15 people.")); ErrorDump.debug(SmartString.class, splitString("123-5678-xxx-yyy-910-223-yyy-910-223")); ErrorDump.debug(SmartString.class, splitString("*****@*****.**")); ErrorDump.debug(SmartString.class, splitString("http://www.google.com")); ErrorDump.debug(SmartString.class, splitString("www.google.com")); Pattern p = Pattern.compile("(l\\+\\\\.){2,}"); Matcher m = p.matcher("l+\\.l+\\.l+"); ErrorDump.debug(SmartString.class, String.valueOf(m.find())); ErrorDump.debug(SmartString.class, splitString("SmartString.class is a longer text.")); ErrorDump.debug(SmartString.class, splitString("123456789")); ErrorDump.debug(SmartString.class, splitString("mIx12eD")); ErrorDump.debug(SmartString.class, splitString("1+1=3")); }