當前位置: 首頁>>代碼示例>>Java>>正文


Java Pattern.split方法代碼示例

本文整理匯總了Java中java.util.regex.Pattern.split方法的典型用法代碼示例。如果您正苦於以下問題:Java Pattern.split方法的具體用法?Java Pattern.split怎麽用?Java Pattern.split使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.util.regex.Pattern的用法示例。


在下文中一共展示了Pattern.split方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: get2InString

import java.util.regex.Pattern; //導入方法依賴的package包/類
/**
 * @param style
 *            類型
 * @return 用逗號,或者分號截取字符串前兩個(這個方法用於類型的字符串截取)
 */
public static String get2InString(String style) {
    Pattern pattern = Pattern.compile("[,;]");
    String[] actors = pattern.split(style);
    StringBuffer buffer = new StringBuffer();
    if (actors.length <= 1) {
        buffer.append(actors[0]);
    } else if (actors.length == 2) {
        buffer.append(actors[0]);
        buffer.append(",");
        buffer.append(actors[1]);
    } else if (actors.length >= 3) {
        buffer.append(actors[0]);
        buffer.append(",");
        buffer.append(actors[1]);
        buffer.append(",");
        buffer.append(actors[2]);
    }
    return buffer.toString();
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:StrUtils.java

示例2: process

import java.util.regex.Pattern; //導入方法依賴的package包/類
private ArrayList<String> process(String args[])
{
    ArrayList<String> others = new ArrayList<String>();
    
    final Pattern p = Pattern.compile("=");
    for (int i = 0, cnt = args.length; i < cnt; i++) {
        final String arg = args[i];
        final String[] parts = p.split(arg, 2);
        if (parts[0].startsWith("-"))
            parts[0] = parts[0].substring(1);

        // ArgumentsParser Parameter
        if (PARAMS.contains(parts[0].toLowerCase())) {
            this.params.put(parts[0].toLowerCase(), parts[1]);
        }
        else
            others.add(arg);
    } // FOR
    
    return others;
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:22,代碼來源:AnotherArgumentsParser.java

示例3: parse

import java.util.regex.Pattern; //導入方法依賴的package包/類
/**
 * Parse a description of partition ids and populate a PartitionSet.
 * This supports comma-separated lists (e.g., "1,2,3,4") and 
 * ranges (e.g., "1-4"). You can also mix and match them together 
 * (e.g., "1,2-3,4").
 * @param partitionList
 * @return
 */
public static PartitionSet parse(String partitionList) {
    Pattern HYPHEN_SPLIT = Pattern.compile(Pattern.quote("-"));
    
    // Partition Ranges
    PartitionSet partitions = new PartitionSet();
    for (String p : StringUtil.splitList(partitionList)) {
        int start = -1;
        int stop = -1;
        String range[] = HYPHEN_SPLIT.split(p);
        if (range.length == 2) {
            start = Integer.parseInt(range[0].trim());
            stop = Integer.parseInt(range[1].trim());
        } else {
            start = Integer.parseInt(p.trim());
            stop = start;
        }
        for (int partition = start; partition < stop + 1; partition++) {
            partitions.add(partition);
        } // FOR
    } // FOR
    return (partitions);
}
 
開發者ID:s-store,項目名稱:sstore-soft,代碼行數:31,代碼來源:PartitionSet.java

示例4: split

import java.util.regex.Pattern; //導入方法依賴的package包/類
static String[] split(final String s, final Pattern delimRegex1, final Pattern delimRegex2) {
    String[] parts = delimRegex1.split(s);
    if (parts.length == 1 && s.equals(parts[0])) {
        //delimiter was not contained in string, try second delimiter
        parts = delimRegex2.split(s);
        if (parts.length == 1 && s.equals(parts[0])) {
            //delimiter was not contained in string, we're done
            return parts;
        }
    }
    if (!s.startsWith(parts[0])) {
        //must be delimiter at the start of the string, meaning we have an empty string at the start
        final String[] newParts = new String[parts.length + 1];
        System.arraycopy(parts, 0, newParts, 1, parts.length);
        newParts[0] = "";
        parts = newParts;
    }
    if (!s.endsWith(parts[parts.length - 1])) {
        //must be delimiter at the end of the string, meaning we have an empty string at the end
        parts = Arrays.copyOf(parts, parts.length + 1);
        parts[parts.length - 1] = "";
    }
    return parts;
}
 
開發者ID:tools4j,項目名稱:spockito,代碼行數:25,代碼來源:Strings.java

示例5: queryToMap

import java.util.regex.Pattern; //導入方法依賴的package包/類
public static Map<String, String[]> queryToMap(String query, Pattern andPattern, Pattern equalPattern) {
	Map<String, String[]> parameters = new HashMap<String, String[]>();
	for (String part : andPattern.split(query)) {
		String[] pair = equalPattern.split(part, 2);
		try {
			String key = URLDecoder.decode(pair[0], "UTF-8");
			String value = pair.length > 1 ? URLDecoder.decode(pair[1], "UTF-8") : ""; 
			String[] list = parameters.get(key);
			if (list != null) {
				list = GenericUtils.copyOf(list, list.length + 1);
				list[list.length - 1] = value;
			} else {
				list = new String[]{value};
			}
			parameters.put(key, list);
		} catch (UnsupportedEncodingException e) {
			Engine.logEngine.error("Unable to parse '" + part + "' as parameter", e);
		}
	}
	return parameters;
}
 
開發者ID:convertigo,項目名稱:convertigo-engine,代碼行數:22,代碼來源:URLUtils.java

示例6: testClassesPattern

import java.util.regex.Pattern; //導入方法依賴的package包/類
public void testClassesPattern() {
    Pattern p = CssClassesVisitor.CLASSES_PATTERN;
    CharSequence input = "  one   two ";
    String[] parts = p.split(input);
    assertEquals(3, parts.length);
    assertTrue(parts[0].trim().isEmpty());
    assertEquals("one", parts[1]);
    assertEquals("two", parts[2]);
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:10,代碼來源:CssClassesVisitorTest.java

示例7: testHanPattern

import java.util.regex.Pattern; //導入方法依賴的package包/類
public void testHanPattern() {
    Pattern hanP = Pattern.compile("([\\u4E00-\\u9FD5]+)");
    String sentence = "abc我是中國人bc你好 workd";
    Matcher matcher = hanP.matcher(sentence);
    System.out.println(matcher.matches());
    for (String s : hanP.split(sentence)) {
        System.out.print(s + " / ");
    }
}
 
開發者ID:hongfuli,項目名稱:elasticsearch-analysis-jieba,代碼行數:10,代碼來源:TokenizerTest.java

示例8: tokenize

import java.util.regex.Pattern; //導入方法依賴的package包/類
public static List<String> tokenize(String line) {
    Pattern pattern = Pattern.compile("\\W+");
    String[] split = pattern.split(line.toLowerCase());
    return Arrays.stream(split)
            .map(String::trim)
            .filter(s -> s.length() > 2)
            .collect(Collectors.toList());
}
 
開發者ID:PacktPublishing,項目名稱:Java-Data-Science-Made-Easy,代碼行數:9,代碼來源:TextUtils.java

示例9: tokenizeFilter

import java.util.regex.Pattern; //導入方法依賴的package包/類
public static List<String> tokenizeFilter(String line) {
    Pattern pattern = Pattern.compile("\\W+");
    String[] split = pattern.split(line.toLowerCase());
    return Arrays.stream(split)
            .map(String::trim)
            .filter(s -> s.length() > 2)
            .filter(s -> !isStopword(s))
            .collect(Collectors.toList());
}
 
開發者ID:PacktPublishing,項目名稱:Java-Data-Science-Made-Easy,代碼行數:10,代碼來源:TextUtils.java

示例10: loadFromArgs

import java.util.regex.Pattern; //導入方法依賴的package包/類
public void loadFromArgs(String args[]) {
    if (debug.val) LOG.debug("Loading from commandline input arguments");
    final Pattern split_p = Pattern.compile("=");
    
    final Map<String, String> argsMap = new ListOrderedMap<String, String>();
    for (int i = 0, cnt = args.length; i < cnt; i++) {
        final String arg = args[i];
        final String[] parts = split_p.split(arg, 2);
        if (parts.length == 1) {
            LOG.warn("Unexpected argument format '" + arg + "'");
            continue;
        }
        
        String k = parts[0].toLowerCase();
        String v = parts[1];
        if (k.startsWith("-")) k = k.substring(1);
        
        // 'hstore.tag' is special argument that we use in killstragglers.py 
        if (k.equalsIgnoreCase("tag")) {
            continue;
        // This command is undefined from the commandline
        } else if (v.startsWith("${")) {
            continue;
        // Or this parameter is commented out in Eclipse
        } else if (k.startsWith("#")) {
            continue;
        }
        
        // We want it!
        argsMap.put(k, v);
    } // FOR
    this.loadFromArgs(argsMap);
}
 
開發者ID:s-store,項目名稱:s-store,代碼行數:34,代碼來源:HStoreConf.java

示例11: getProcessInfo

import java.util.regex.Pattern; //導入方法依賴的package包/類
public static Map<String, String> getProcessInfo(String pid, String... args) throws Exception {

        if (args == null || args.length == 0) {
            throw new IllegalArgumentException("args cannot be empty.");
        }

        StringBuilder sb = new StringBuilder();
        sb.append("ps h -o ");
        for (String arg : args) {
            sb.append(arg).append(",");
        }
        sb.setLength(sb.length() - 1);
        sb.append(" -p ").append(pid);

        String rs = RuntimeHelper.exec(sb.toString());
        if (rs == null || rs.length() == 0) {
            return null;
        }

        Pattern p = Pattern.compile("\\s+");
        String[] ss = p.split(rs.trim(), args.length);
        Map<String, String> map = new HashMap<String, String>();
        for (int i = 0; i < ss.length; i++) {
            map.put(args[i], ss[i]);
        }

        return map;
    }
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:29,代碼來源:OSProcessHelper.java

示例12: parsePoints

import java.util.regex.Pattern; //導入方法依賴的package包/類
private static List<Location> parsePoints(String points) {
	Pattern patt = Pattern.compile("[ ,\n\r\t]+");
	String[] toks = patt.split(points);
	Location[] ret = new Location[toks.length / 2];
	for (int i = 0; i < ret.length; i++) {
		int x = Integer.parseInt(toks[2 * i]);
		int y = Integer.parseInt(toks[2 * i + 1]);
		ret[i] = Location.create(x, y);
	}
	return UnmodifiableList.create(ret);
}
 
開發者ID:LogisimIt,項目名稱:Logisim,代碼行數:12,代碼來源:SvgReader.java

示例13: add

import java.util.regex.Pattern; //導入方法依賴的package包/類
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);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:36,代碼來源:CurveDB.java

示例14: split

import java.util.regex.Pattern; //導入方法依賴的package包/類
public static List<String[]> split(String message, Pattern DELIMITER){
	List<String[]> list = new ArrayList<String[]>();
	String[] lines = message.split("\n");
	for (String line : lines) {
		String[] splits = DELIMITER.split(line.trim());
		list.add(splits);
	}
	return list;
}
 
開發者ID:yanfanvip,項目名稱:RedisClusterManager,代碼行數:10,代碼來源:Convert.java

示例15: splitQuery

import java.util.regex.Pattern; //導入方法依賴的package包/類
private String[] splitQuery(String query) {
  Pattern delimiterPattern = Pattern.compile("((?<= and )|(?= and )|(?<= or )|(?= or ))", Pattern.CASE_INSENSITIVE);
  String[] parts = delimiterPattern.split(query);

  for (int i = 0; i < parts.length; i++) {
    parts[i] = parts[i].trim();
  }

  return parts;
}
 
開發者ID:Juraji,項目名稱:Biliomi,代碼行數:11,代碼來源:RestFilterQueryParser.java


注:本文中的java.util.regex.Pattern.split方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。