Java Code Examples for java.util.regex.Pattern#split()

The following examples show how to use java.util.regex.Pattern#split() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringPar.java    From PracticeDemo with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) {


//        String content = "aole734c433198fd6b30://sourceapp=TaoLe.DouDiZhu&sourceappname=碰碰车&sourcescheme=taoledoudizhu&pic=http://s.5dktv.com/public/image/ddz_logo.png";
        String content = "aole734c433198fd6b30://sourceapp=TaoLe.DouDiZhu&sourceappname=碰碰车&sourcescheme=taoledoudizhu&pic=http://s.5dktv.com/public/image/ddz_logo.png";

        String regex = "=[*]+^&";
//        String regex = "(?<=\\=(.+?)(?=\\&)";
//        String regex = "=[*]+&";
//        String regex = "app";
        Pattern p = Pattern.compile(regex);
        Matcher matcher = p.matcher(content);
        boolean ma = matcher.matches();
        String[] results = p.split(content);
        for (String result : results) {
            System.out.println(result);
        }
    }
 
Example 2
Source File: StatementPlanDUnit.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
public final static String distribution(String input, int numMembers) {
  StringBuilder patternString = new StringBuilder();
  // DISTRIBUTION to 3 members took 3210 microseconds ( message sending
  // min/max/avg time 535/952/2036 microseconds and receiving min/max/avg time
  // 171/1067/1444 microseconds )
  patternString = new StringBuilder();
  patternString
      .append("\\s*DISTRIBUTION to\\s*"
          + numMembers
          + "\\s*members took [0-9]([0-9]*)? microseconds\\s*\\( "
          + "message sending min/max/avg time [0-9]([0-9]*)?/[0-9]([0-9]*)?/[0-9]([0-9]*)? microseconds and "
          + "receiving min/max/avg time [0-9]([0-9]*)?/[0-9]([0-9]*)?/[0-9]([0-9]*)? microseconds \\)");

  Pattern planMatcher = Pattern.compile(patternString.toString(),
      Pattern.MULTILINE);

  final String[] distributionDone = planMatcher.split(input);
  getLogWriter().info(java.util.Arrays.toString(distributionDone));
  assertEquals(2, distributionDone.length);
  return distributionDone[1];
}
 
Example 3
Source File: PatternTest.java    From j2objc with Apache License 2.0 6 votes vote down vote up
public void testSplitCharSequenceZeroLimit() {
    String[] s;
    Pattern pat = Pattern.compile("b");

    s = pat.split("abccbadfebb", 0);
    assertEquals(s.length, 3);
    s = pat.split("", 0);
    assertEquals(s.length, 1);
    /* J2ObjC removed: empty pattern is invalid in ICU 51. (b/12096792)
    pat = Pattern.compile("");
    s = pat.split("", 0);
    assertEquals(s.length, 1);
    s = pat.split("abccbadfe", 0);
    assertEquals(s.length, 9);
    */
}
 
Example 4
Source File: FragmentCalculation.java    From Juicebox with MIT License 6 votes vote down vote up
private static FragmentCalculation readFragments(InputStream is, ChromosomeHandler handler) throws IOException {
    Pattern pattern = Pattern.compile("\\s");
    BufferedReader reader = new BufferedReader(new InputStreamReader(is), HiCGlobals.bufferSize);
    String nextLine;
    Map<String, int[]> sitesMap = new LinkedHashMap<>();

    while ((nextLine = reader.readLine()) != null) {
        String[] tokens = pattern.split(nextLine);
        if (tokens.length > 1) {
            String key = tokens[0];
            int[] sites = new int[tokens.length - 1];
            for (int i = 1; i < tokens.length; i++) {
                sites[i - 1] = Integer.parseInt(tokens[i]);
            }

            sitesMap.put(handler.cleanUpName(key), sites);
        } else {
            System.out.println("Skipping line: " + nextLine);
        }
    }

    return new FragmentCalculation(sitesMap);
}
 
Example 5
Source File: Utility.java    From fitnotifications with Apache License 2.0 5 votes vote down vote up
/**
 * Parse a list of hex numbers and return a string
 * @param string String of hex numbers.
 * @param minLength Minimal length.
 * @param separator Separator.
 * @return A string from hex numbers.
 */
public static String fromHex(String string, int minLength, Pattern separator) {
    StringBuilder buffer = new StringBuilder();
    String[] parts = separator.split(string);
    for (String part : parts) {
        if (part.length() < minLength) {
            throw new IllegalArgumentException("code point too short: " + part);
        }
        int cp = Integer.parseInt(part, 16);
        buffer.appendCodePoint(cp);
    }
    return buffer.toString();
}
 
Example 6
Source File: StatementPlanDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public final static String regiongetall(String input, int numRows) {
  StringBuilder patternString = new StringBuilder();
  // REGION-GETALL of 2 rows took 2315 microseconds
  patternString = new StringBuilder();
  patternString.append("\\s*REGION-GETALL of\\s*" + numRows
      + "\\s*rows took [0-9]([0-9]*)? ");
  Pattern planMatcher = Pattern.compile(patternString.toString(),
      Pattern.MULTILINE);

  final String[] getallDone = planMatcher.split(input);
  getLogWriter().info("regiongetall:" + java.util.Arrays.toString(getallDone));
  assertEquals("microseconds", getallDone[1].trim());
  return getallDone[1];
}
 
Example 7
Source File: CurveDB.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void add(String name, String soid, int type, String sfield,
        String a, String b, String x, String y, String n, int h,
        Pattern nameSplitPattern) {
    BigInteger p = bi(sfield);
    ECField field;
    if ((type == P) || (type == PD)) {
        field = new ECFieldFp(p);
    } else if ((type == B) || (type == BD)) {
        field = new ECFieldF2m(p.bitLength() - 1, p);
    } else {
        throw new RuntimeException("Invalid type: " + type);
    }

    EllipticCurve curve = new EllipticCurve(field, bi(a), bi(b));
    ECPoint g = new ECPoint(bi(x), bi(y));

    NamedCurve params = new NamedCurve(name, soid, curve, g, bi(n), h);
    if (oidMap.put(soid, params) != null) {
        throw new RuntimeException("Duplication oid: " + soid);
    }

    String[] commonNames = nameSplitPattern.split(name);
    for (String commonName : commonNames) {
        if (nameMap.put(commonName.trim(), params) != null) {
            throw new RuntimeException("Duplication name: " + commonName);
        }
    }

    int len = field.getFieldSize();
    if ((type == PD) || (type == BD) || (lengthMap.get(len) == null)) {
        // add entry if none present for this field size or if
        // the curve is marked as a default curve.
        lengthMap.put(len, params);
    }
}
 
Example 8
Source File: StatementPlanDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public final static String rowidscan(String input, String rows,
    String numOpens) {
  // "  ROWIDSCAN (0.00%) execute time 25.820 ms returned_rows 56 no_opens 1"+
  StringBuilder patternString = new StringBuilder();
  patternString = new StringBuilder();
  patternString.append("ROWIDSCAN ").append(optionalPercentage).
      append(" execute_time\\s*").append(executeMillis).
      append("\\s*returned_rows\\s*" + rows + "\\s*no_opens\\s*" + numOpens);
  Pattern planMatcher = Pattern.compile(patternString.toString(),
      Pattern.MULTILINE);
  String[] rowIDScanDone = planMatcher.split(input);
  getLogWriter().info(java.util.Arrays.toString(rowIDScanDone));
  assertEquals(2, rowIDScanDone.length);
  return rowIDScanDone[1];
}
 
Example 9
Source File: DownloadUtil.java    From tinker-manager with Apache License 2.0 5 votes vote down vote up
public static String getFileNameFromUrl(String url) {
    Pattern p = Pattern.compile("[^/]*$");
    String[] str = p.split(url);
    String before = str[0];
    String after = url.substring(str[0].length());
    return after == null ? "" : after;
}
 
Example 10
Source File: StatementPlanDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public final static String resultHolder2(String input, String rows,
    int numOpens) {
  // RESULT-HOLDER execute_time 20.5449 ms returned_rows 2 no_opens 1
  StringBuilder patternString = new StringBuilder();
  patternString = new StringBuilder();
  patternString.append("\\s*RESULT-HOLDER\\s*execute_time ").append(
      executeMillis).append(
      " returned_rows\\s*" + rows + "\\s*no_opens\\s*" + numOpens);
  Pattern planMatcher = Pattern.compile(patternString.toString(),
      Pattern.MULTILINE);
  String[] resultHolderDone = planMatcher.split(input, 2);
  getLogWriter().info(java.util.Arrays.toString(resultHolderDone));
  assertEquals(2, resultHolderDone.length);
  return resultHolderDone[1];
}
 
Example 11
Source File: StatementPlanDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public final static String roundrobin(String input, int numRows) {
  StringBuilder patternString = new StringBuilder();
  // ROUNDROBIN-ITERATION of 5 rows took 88738 microseconds
  patternString = new StringBuilder();
  patternString.append("\\s*ROUNDROBIN-ITERATION of\\s*" + numRows
      + "\\s*rows took [0-9]([0-9]*)? microseconds");
  Pattern planMatcher = Pattern.compile(patternString.toString(),
      Pattern.MULTILINE);

  final String[] roundRobinDone = planMatcher.split(input);
  getLogWriter().info(java.util.Arrays.toString(roundRobinDone));
  assertEquals(2, roundRobinDone.length);
  return roundRobinDone[1];
}
 
Example 12
Source File: CurveDB.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void add(String name, String soid, int type, String sfield,
        String a, String b, String x, String y, String n, int h,
        Pattern nameSplitPattern) {
    BigInteger p = bi(sfield);
    ECField field;
    if ((type == P) || (type == PD)) {
        field = new ECFieldFp(p);
    } else if ((type == B) || (type == BD)) {
        field = new ECFieldF2m(p.bitLength() - 1, p);
    } else {
        throw new RuntimeException("Invalid type: " + type);
    }

    EllipticCurve curve = new EllipticCurve(field, bi(a), bi(b));
    ECPoint g = new ECPoint(bi(x), bi(y));

    NamedCurve params = new NamedCurve(name, soid, curve, g, bi(n), h);
    if (oidMap.put(soid, params) != null) {
        throw new RuntimeException("Duplication oid: " + soid);
    }

    String[] commonNames = nameSplitPattern.split(name);
    for (String commonName : commonNames) {
        if (nameMap.put(commonName.trim(), params) != null) {
            throw new RuntimeException("Duplication name: " + commonName);
        }
    }

    int len = field.getFieldSize();
    if ((type == PD) || (type == BD) || (lengthMap.get(len) == null)) {
        // add entry if none present for this field size or if
        // the curve is marked as a default curve.
        lengthMap.put(len, params);
    }
}
 
Example 13
Source File: StatementPlanDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public final static String sort(String input, String rows, int numOpens) {
  // "SORT (0.00%) execute_time 67.218 ms input_rows 56 returned_rows 56 no_opens 1 sort_type IN sorter_output 56"+
  StringBuilder patternString = new StringBuilder();
  patternString = new StringBuilder();
  patternString.append("SORT ").append(optionalPercentage).
      append(" execute_time\\s*").append(executeMillis).append("\\s*input_rows " + rows + "\\s*returned_rows\\s*" + rows
          + "\\s*no_opens\\s*" + numOpens + " sort_type IN sorter_output\\s*" + rows);
  Pattern planMatcher = Pattern.compile(patternString.toString(),
      Pattern.MULTILINE);
  String[] sortDone = planMatcher.split(input);
  getLogWriter().info(java.util.Arrays.toString(sortDone));
  assertEquals(2, sortDone.length);
  return sortDone[1];
}
 
Example 14
Source File: StatementPlanDUnit.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
public final static String resultHolder2(String input, String rows,
    int numOpens) {
  // RESULT-HOLDER execute_time 20.5449 ms returned_rows 2 no_opens 1
  StringBuilder patternString = new StringBuilder();
  patternString = new StringBuilder();
  patternString.append("\\s*RESULT-HOLDER\\s*execute_time ").append(
      executeMillis).append(
      " returned_rows\\s*" + rows + "\\s*no_opens\\s*" + numOpens);
  Pattern planMatcher = Pattern.compile(patternString.toString(),
      Pattern.MULTILINE);
  String[] resultHolderDone = planMatcher.split(input, 2);
  getLogWriter().info(java.util.Arrays.toString(resultHolderDone));
  assertEquals(2, resultHolderDone.length);
  return resultHolderDone[1];
}
 
Example 15
Source File: SimpleShortestPathsComputationTest.java    From hgraphdb with Apache License 2.0 5 votes vote down vote up
private Map<Long, Double> parseDistances(Iterable<String> results) {
    Map<Long, Double> distances =
            Maps.newHashMapWithExpectedSize(Iterables.size(results));

    Pattern separator = Pattern.compile("[\t]");

    for (String line : results) {
        String[] tokens = separator.split(line);
        distances.put(Long.parseLong(tokens[0]), Double.parseDouble(tokens[1]));
    }
    return distances;
}
 
Example 16
Source File: JarEntry.java    From baratine with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Validates the manifest.
 */
public static void validateManifest(String manifestName, Manifest manifest)
  throws ConfigException
{
  Attributes attr = manifest.getMainAttributes();
  if (attr == null)
    return;

  String extList = attr.getValue("Extension-List");
  if (extList == null)
    return;

  Pattern pattern = Pattern.compile("[, \t]+");
  String []split = pattern.split(extList);

  for (int i = 0; i < split.length; i++) {
    String ext = split[i];

    String name = attr.getValue(ext + "-Extension-Name");
    if (name == null)
      continue;

    Package pkg = Package.getPackage(name);

    if (pkg == null) {
      log.warning(L.l("package {0} is missing.  {1} requires package {0}.",
                      name, manifestName));
      continue;
    }

    String version = attr.getValue(ext + "-Specification-Version");

    if (version == null)
      continue;

    if (pkg.getSpecificationVersion() == null ||
        pkg.getSpecificationVersion().equals("")) {
      log.warning(L.l("installed {0} is not compatible with version `{1}'.  {2} requires version {1}.",
                   name, version, manifestName));
    }
    else if (! pkg.isCompatibleWith(version)) {
      log.warning(L.l("installed {0} is not compatible with version `{1}'.  {2} requires version {1}.",
                   name, version, manifestName));
    }
  }
}
 
Example 17
Source File: SplitTest.java    From j2objc with Apache License 2.0 4 votes vote down vote up
public void testSimple() {
    Pattern p = Pattern.compile("/");
    String[] results = p.split("have/you/done/it/right");
    String[] expected = new String[] { "have", "you", "done", "it", "right" };
    assertArraysEqual(expected, results);
}
 
Example 18
Source File: EvalAttributeFunction.java    From olat with Apache License 2.0 4 votes vote down vote up
/**
 * Searches expression <code>ex</code> in multivalue enabled attribute value <code>values</code>
 * 
 * @param ex
 *            The expression to search for.
 * @param values
 *            The attribute value(s), separated by ,
 * @return true if found, false otherwise
 * @author Lars Eberle (<a href="http://www.bps-system.de/">BPS Bildungsportal Sachsen GmbH</a>)
 */
private boolean findExpressionInMultiValue(final String ex, final String values, final int type) {
    try {
        if (ex == null || values == null) {
            return false; // empty params?
        }
        final Pattern multiValueSeparatorEx = Pattern.compile(",");
        final String[] a = multiValueSeparatorEx.split(ex); // split on ,
        final Pattern multiValueSeparatorValue = Pattern.compile(";");
        final String[] b = multiValueSeparatorValue.split(values); // split on ;
        if (a == null || (a.length == 1 && a[0] == "")) {
            return false; // empty array?
        }
        if (b == null || (b.length == 1 && b[0] == "")) {
            return false; // empty array?
        }
        if (log.isDebugEnabled()) {
            log.debug("a: " + Arrays.toString(a));
            log.debug("b: " + Arrays.toString(b));
        }
        if (type == FUNCTION_TYPE_HAS_ATTRIBUTE) {
            final List<String> l = Arrays.asList(a);
            if (l.retainAll(Arrays.asList(b))) {
                return true; // all values are the same -> excellent :-)
            }
            if (!l.isEmpty()) {
                return true; // some equally values found, return true
                // l now contains all values which were also contained in values param, so if you want to work with that...
            }
        } else if (type == FUNCTION_TYPE_ATTRIBUTE_STARTS_WITH) {
            for (int i = 0; i < a.length; ++i) { // for every attribute value
                for (int j = 0; j < b.length; ++j) {
                    if ((b[j].startsWith(a[i]))) {
                        return true; // if match then return true
                    }
                }
            }
        } else if (type == FUNCTION_TYPE_ATTRIBUTE_ENDS_WITH) {
            for (int i = 0; i < a.length; ++i) { // for every attribute value
                for (int j = 0; j < b.length; ++j) {
                    if ((b[j].endsWith(a[i]))) {
                        return true; // if match then return true
                    }
                }
            }
        } else if (type == FUNCTION_TYPE_IS_IN_ATTRIBUTE) {
            for (int i = 0; i < a.length; ++i) { // for every attribute value
                for (int j = 0; j < b.length; ++j) {
                    if ((b[j].indexOf(a[i])) > -1) {
                        return true; // if match then return true
                    }
                }
            }
        } else if (type == FUNCTION_TYPE_IS_NOT_IN_ATTRIBUTE) {
            boolean somethingFound = false;
            for (int i = 0; i < a.length; ++i) { // for every attribute value
                for (int j = 0; j < b.length; ++j) {
                    if ((b[j].indexOf(a[i])) > -1) {
                        somethingFound = true; // if match then return true
                    }
                }
            }
            return !somethingFound;
        }
        return false; // only return false if nothing found
    } catch (final Exception e) {
        return false; // some String was null or something else unexpected
    }
}
 
Example 19
Source File: StrUtils.java    From SDA with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static String[] regSplit(String input, String seperator)
{
	Pattern p = Pattern.compile(seperator);
	return p.split(input.toString());
}
 
Example 20
Source File: StringUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
/**
 * Splits a newline (\n) delimited string into an array of strings
 *
 * @param str the string to split up
 * @param delimiter the delimiter to use in splitting
 * @return an array of String objects equivalent to str
 */
public String[] splitDelimitedStr(String str, String delimiter) {
    Pattern pttn = Pattern.compile(delimiter);
    return pttn.split(str);
}