当前位置: 首页>>代码示例>>Java>>正文


Java Pattern.compile方法代码示例

本文整理汇总了Java中java.util.regex.Pattern.compile方法的典型用法代码示例。如果您正苦于以下问题:Java Pattern.compile方法的具体用法?Java Pattern.compile怎么用?Java Pattern.compile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.regex.Pattern的用法示例。


在下文中一共展示了Pattern.compile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: replaceParameter

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * 替换url中参数的值。
 */
public static String replaceParameter(String query, String key, String value) {
    if (query == null || query.length() == 0) {
        return key + "=" + value;
    }
    if (query.indexOf(key + "=") == -1) {
    	return query + "&" + key + "=" + value;
    }
    Pattern pattern = REPLACE_PARAMETER_PATTERNS.get(key);
    if (pattern == null) {
    	pattern = Pattern.compile(key.replaceAll("([^(_0-9A-Za-z)])", "\\\\$0") + "=[^&]+");
    }
    Matcher matcher = pattern.matcher(query);
    StringBuffer sb = new StringBuffer();
    while (matcher.find()) {
        matcher.appendReplacement(sb, (key + "=" + value).replace("$", "\\$"));
    }
    matcher.appendTail(sb);
    return sb.toString();
}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:23,代码来源:ParseUtils.java

示例2: denomMatchers

import java.util.regex.Pattern; //导入方法依赖的package包/类
ScaleMatcher[] denomMatchers() {
    ScaleMatcher[] result = denoms;
    if (result == null) { synchronized(this) {
        result = denoms;
        if (result == null) {
            if (! coinSymbol().matches(ci)) ci = ci.replaceFirst("\\(", "(" + coinSymbol() + "|");
            if (! coinCode().matches(ci))  {
                ci = ci.replaceFirst("\\)", "|" + coinCode() + ")");
            }
            coinPattern = Pattern.compile(ci + "?");
            result = denoms = new ScaleMatcher[]{
                new ScaleMatcher(Pattern.compile("¢" + ci + "?|c" + ci), 2), // centi 
                new ScaleMatcher(Pattern.compile("₥" + ci + "?|m" + ci), MILLICOIN_SCALE),
                new ScaleMatcher(Pattern.compile("([µu]" + ci + ")"),    MICROCOIN_SCALE),
                new ScaleMatcher(Pattern.compile("(da" + ci + ")"),     -1), // deka
                new ScaleMatcher(Pattern.compile("(h" + ci + ")"),      -2), // hekto
                new ScaleMatcher(Pattern.compile("(k" + ci + ")"),      -3), // kilo
                new ScaleMatcher(Pattern.compile("(M" + ci + ")"),      -6)  // mega
            };
        }
    }}
    return result;
}
 
开发者ID:guodroid,项目名称:okwallet,代码行数:24,代码来源:BtcFormat.java

示例3: extractEscapedComments

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * Returns a list which contains comments of the string entry in the constant pool
 * and the appropriate UTF-8 value.
 *
 * @return a list
 */
private List<String> extractEscapedComments(String output) {
    List<String> result = new ArrayList<>();
    Pattern stringPattern = Pattern.compile(" +#\\d+ = String +#(\\d+) +// +(.*)");
    int index = -1;
    List<String> cp = extractConstantPool(output);
    for (String c : cp) {
        Matcher matcher = stringPattern.matcher(c);
        if (matcher.matches()) {
            index = Integer.parseInt(matcher.group(1)) - 1;
            result.add(matcher.group(2));
            // only one String entry
            break;
        }
    }
    check(index == -1, "Escaped string is not found in constant pool");
    result.add(cp.get(index).replaceAll(".* +", "")); // remove #16 = Utf8
    return result;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:25,代码来源:T8038414.java

示例4: compareBranches

import java.util.regex.Pattern; //导入方法依赖的package包/类
protected int compareBranches() {
	String val1 = ((StringNode) left).getValue();
	String val2 = ((StringNode) right).getValue();

	int val2Len = val2.length();
	if (val2Len > 1 && val2.charAt(0) == '/' && val2.charAt(val2Len - 1) == '/') {
		// Treat as a regular expression
		String expr = val2.substring(1, val2Len - 1);
		try {
			Pattern pattern = Pattern.compile(expr);
			// Regular expressions will only ever be used with EqualNode
			// so return zero for equal and non-zero for not equal
			if (pattern.matcher(val1).find()) {
				return 0;
			} else {
				return -1;
			}
		} catch (PatternSyntaxException pse) {
			ssiMediator.log("Invalid expression: " + expr, pse);
			return 0;
		}
	}
	return val1.compareTo(val2);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:25,代码来源:ExpressionParseTree.java

示例5: getNameSpace

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * UserDataの名前空間を取得する.
 * @param entityType エンティティタイプ名
 * @param col コレクション名
 * @return UserDataの名前空間
 */
protected String getNameSpace(String entityType, String col) {
    // NameSpace取得のためにメタデータを取得する
    TResponse res = Http.request("box/$metadata-$metadata-get.txt")
            .with("path", "\\$metadata")
            .with("col", col)
            .with("accept", "application/xml")
            .with("token", PersoniumUnitConfig.getMasterToken())
            .returns()
            .statusCode(HttpStatus.SC_OK)
            .debug();
    Pattern pattern = Pattern.compile("Namespace=\"([^\"]+)\">");
    Matcher matcher = pattern.matcher(res.getBody());
    matcher.find();
    return matcher.group(1) + "." + entityType;
}
 
开发者ID:personium,项目名称:personium-core,代码行数:22,代码来源:AbstractUserDataTest.java

示例6: Finder

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * Constructor for Finder.
 */
public Finder(
    HTMLEditor theEditor,
    String find,
    boolean wholeWord,
    boolean matchCase,
    boolean regexp,
    String replace) {
    super();
    editor = theEditor;
    dispText = find;
    int flags = Pattern.DOTALL;
    if (!matchCase)
        flags = flags + Pattern.CASE_INSENSITIVE + Pattern.UNICODE_CASE;
    _find = find;
    if (!regexp)
        _find = "\\Q" + _find + "\\E";
    if (wholeWord)
        _find = "[\\s\\p{Punct}]" + _find + "[\\s\\p{Punct}]";
    try {
        pattern = Pattern.compile(_find, flags);
    }
    catch (Exception ex) {
        ex.printStackTrace();
        pattern = null;
    }
    _replace = replace;
}
 
开发者ID:ser316asu,项目名称:SER316-Ingolstadt,代码行数:31,代码来源:Finder.java

示例7: parseSubjectPermissions

import java.util.regex.Pattern; //导入方法依赖的package包/类
private Map<Long, Set<String>> parseSubjectPermissions(Properties properties, long subjectID) {
  Map<Long, Set<String>> permissions = new HashMap<>();

  Pattern permissionPattern = Pattern.compile(SUBJECT_PERMISSION_KEY.replace("{id}", String.valueOf(subjectID)));
  for (String key : properties.stringPropertyNames()) {
    Matcher matcher = permissionPattern.matcher(key);
    if (!matcher.matches()) continue;
    // Extract organizationID from key and parse function (group) names.
    permissions.put(Long.parseUnsignedLong(matcher.group(1)), parseStringMembers(properties, key));
  }

  return permissions;
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:14,代码来源:PropertiesFileParser.java

示例8: isValid

import java.util.regex.Pattern; //导入方法依赖的package包/类
@Override
public boolean isValid(final Object value, ConstraintValidatorContext context) {
    if (value == null || "".equals(value)) {
        return true;
    } else if (!StringUtil.isEmpty(validateRegexp.regexp())) {
        Pattern pattern = Pattern.compile(validateRegexp.regexp());
        Matcher matcher = pattern.matcher(value.toString().replaceAll("/", ""));
        return matcher.matches();
    }
    return false;
}
 
开发者ID:DomKing,项目名称:springbootWeb,代码行数:12,代码来源:ValidateRegexpValidator.java

示例9: main

import java.util.regex.Pattern; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException{
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    StringBuilder string = new StringBuilder();
    string.append(reader.readLine());
    String regex = "(?<num>(\\d+)|^)(?<op>[^0-9]+|$)";
    Pattern pattern = Pattern.compile(regex);
    Matcher matcher = pattern.matcher(string);
    Double result = 0d;
    boolean plus = true;
    while(matcher.find()){
        /*System.out.println("full match " + matcher.group(0));
        System.out.println("num is " + matcher.group("num"));
        System.out.println("operator is " + (matcher.group("op").length() % 2 == 0 ? "+" : "-"));*/
        Double num = 0d;
        if(!matcher.group("num").isEmpty()){
            num = Double.parseDouble(matcher.group("num"));
        }
        if(plus){
            result += num;
        } else {
            result -= num;
        }
        plus = matcher.group("op").length() % 2 == 0;
    }
    DecimalFormat myFormat = new DecimalFormat("0.#######");
    System.out.println(myFormat.format(result));
}
 
开发者ID:kostovhg,项目名称:SoftUni,代码行数:28,代码来源:p02_LetterExpression.java

示例10: globItem

import java.util.regex.Pattern; //导入方法依赖的package包/类
private Set<Index> globItem(String item, Set<Index> full)
{
    Set<Index> ret = new HashSet<Index>();
    Pattern glob = Pattern.compile('^' + item.trim().replace("*", ".*") + '$');
    for (Index idx : full) {
        if (glob.matcher(idx.getCode()).find())
            ret.add(idx);
    }
    return ret;
}
 
开发者ID:drytoastman,项目名称:scorekeeperfrontend,代码行数:11,代码来源:ClassData.java

示例11: match

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * <p>正则提取匹配到的内容</p>
 * <p>例如:</p>
 * </br>
 * author : Crab2Died</br>
 * date   : 2017年06月02日  15:49:51</br>
 *
 * @param pattern 匹配目标内容
 * @param reg     正则表达式
 * @param group   提取内容索引
 * @return 提取内容集合
 * @throws {@link RuntimeException}
 */
static
public List<String> match(String pattern, String reg, int group)
        throws RuntimeException {

    List<String> matchGroups = new ArrayList<>();
    Pattern compile = Pattern.compile(reg);
    Matcher matcher = compile.matcher(pattern);
    if (group > matcher.groupCount() || group < 0)
        throw new RuntimeException("Illegal match group :" + group);
    while (matcher.find()) {
        matchGroups.add(matcher.group(group));
    }
    return matchGroups;
}
 
开发者ID:zhangbiy,项目名称:exportExcel,代码行数:28,代码来源:RegularUtils.java

示例12: fiterHtmlTag

import java.util.regex.Pattern; //导入方法依赖的package包/类
/**
 * 基本功能:过滤指定标签
 *
 * @param str
 * @param tag 指定标签
 * @return String
 */
public static String fiterHtmlTag(String str, String tag) {
    String regxp = "<\\s*" + tag + "\\s+([^>]*)\\s*>";
    Pattern pattern = Pattern.compile(regxp);
    Matcher matcher = pattern.matcher(str);
    StringBuffer sb = new StringBuffer();
    boolean result1 = matcher.find();
    while (result1) {
        matcher.appendReplacement(sb, "");
        result1 = matcher.find();
    }
    matcher.appendTail(sb);
    return sb.toString();
}
 
开发者ID:hsj-xiaokang,项目名称:OSchina_resources_android,代码行数:21,代码来源:HTMLUtil.java

示例13: test26

import java.util.regex.Pattern; //导入方法依赖的package包/类
@Test(timeout = 4000)
public void test26() throws Throwable {
  Configuration configuration0 = new Configuration();
  Pattern pattern0 = Pattern.compile("7e:P");
  configuration0.setAllowPartitionNameFilter(pattern0);
  Pattern pattern1 = configuration0.getAllowPartitionNameFilter();
  assertEquals(0, pattern1.flags());
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:9,代码来源:ConfigurationTest.java

示例14: createClassGlobPattern

import java.util.regex.Pattern; //导入方法依赖的package包/类
private static Pattern createClassGlobPattern(String pattern) {
    if (pattern.length() == 0) {
        return null;
    } else if (pattern.contains(".")) {
        return Pattern.compile(createGlobString(pattern));
    } else {
        return Pattern.compile("([^\\.\\$]*[\\.\\$])*" + createGlobString(pattern));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:MethodFilter.java

示例15: parse

import java.util.regex.Pattern; //导入方法依赖的package包/类
public BasicDBObject parse(IRule rule, JsonRuleParser parser) {
    BasicDBObject operate = new BasicDBObject("$regex", Pattern.compile("(?<!" + rule.getValue() + ")$"));
    return new BasicDBObject(rule.getField(), operate);
}
 
开发者ID:itfsw,项目名称:QueryBuilder,代码行数:5,代码来源:NotEndsWithRuleParser.java


注:本文中的java.util.regex.Pattern.compile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。