当前位置: 首页>>代码示例>>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;未经允许,请勿转载。