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


Java Pattern类代码示例

本文整理汇总了Java中com.google.code.regexp.Pattern的典型用法代码示例。如果您正苦于以下问题:Java Pattern类的具体用法?Java Pattern怎么用?Java Pattern使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: testParcel

import com.google.code.regexp.Pattern; //导入依赖的package包/类
@Test
public void testParcel() {
    Parcel parcel = Parcel.obtain();

    CompiledRoute compiledRoute = new CompiledRoute();
    compiledRoute.setVariables(Arrays.asList("vendor", "repository"))
            .setRegex(Pattern.compile("hello"))
            .setConstantUrl("constantUrl")
            .setType(Route.TYPE_DIRECTLY)
            .setActivityClass(Activity.class.getName())
            .setProxyDestIdentify("ha")
            .setMiddlewares(Arrays.asList("a", "b"))
            .setAnchor("comments")
            .setSchemes(Arrays.asList("vendor", "repository"));
    compiledRoute.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);

    CompiledRoute compiledRouteFromParcel = new CompiledRoute(parcel);

    assertTrue("-> test parcelable", compiledRoute.equals(compiledRouteFromParcel));

    assertEquals("b", compiledRoute.getNextMiddleware("a"));
    assertNull(compiledRoute.getNextMiddleware("b"));
    assertNull(compiledRoute.getNextMiddleware("c"));
}
 
开发者ID:mr5,项目名称:android-router,代码行数:26,代码来源:RouteCompilerImplTest.java

示例2: RegexpData

import com.google.code.regexp.Pattern; //导入依赖的package包/类
public RegexpData(Context context) {
    Map<String, String> subProperties = context.getSubProperties(CUSTOM_REGEXPS);

    this.isUrlEncoded = context.getBoolean("regexp.is.urlencoded", false);

    for (Map.Entry<String, String> entry : subProperties.entrySet()) {
        try {
            regexpMap.put(entry.getKey(), Pattern.compile(
                (this.isUrlEncoded) ?
                    URLDecoder.decode(entry.getValue(), "UTF-8") :
                    entry.getValue()));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
    }

    this.regexpKey = context.getInteger("custom.group.regexp.key", 1);
    this.regexpValue = context.getInteger("custom.group.regexp.value", 2);
}
 
开发者ID:keedio,项目名称:flume-enrichment-interceptor-skeleton,代码行数:20,代码来源:RegexpData.java

示例3: testMatchFiles_several_Regexp

import com.google.code.regexp.Pattern; //导入依赖的package包/类
public void testMatchFiles_several_Regexp() {
    System.out.println("matchFiles_several_Regexp");

    Path file = Paths.get("src/test/resources/file.log");

    Map<String, String> regexpMap = new HashMap<>();
    Map<String, String> matchesMap = new HashMap<>();

    regexpMap.put("1", "(?<date>\\d{4}-\\d{2}-\\d{2}+)\\s");
    regexpMap.put("2", "(?<time>\\d{2}:\\d{2}:\\d{2}+)\\s");

    try {
        List<String> linesfile = Files.readAllLines(file, Charset.defaultCharset());
        for (String line : linesfile) {
            for (String regexp : regexpMap.values()) {
                Matcher m = Pattern.compile(regexp).matcher(line);
                matchesMap.putAll(m.namedGroups());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println(matchesMap);

}
 
开发者ID:keedio,项目名称:flume-enrichment-interceptor-skeleton,代码行数:27,代码来源:RegexpDataTest.java

示例4: Route

import com.google.code.regexp.Pattern; //导入依赖的package包/类
public Route(String http_method,
             String url_pattern_raw,
             Pattern url_pattern,
             String summary,
             Class<? extends Handler> handler_class,
             Method handler_method,
             Method doc_method,
             String[] path_params,
             HandlerFactory handler_factory) {
  assert http_method != null && url_pattern != null && handler_class != null && handler_method != null && path_params != null;
  assert handler_factory != null : "handler_factory should be not null, caller has to pass it!";
  _http_method = http_method;
  _url_pattern_raw = url_pattern_raw;
  _url_pattern = url_pattern;
  _summary = summary;
  _handler_class = handler_class;
  _handler_method = handler_method;
  _doc_method = doc_method;
  _path_params = path_params;
  _handler_factory = handler_factory;
  try {
    _handler = _handler_factory.create(_handler_class);
  } catch (Exception e) {
    throw H2O.fail("Could not create handler", e);
  }
}
 
开发者ID:kyoren,项目名称:https-github.com-h2oai-h2o-3,代码行数:27,代码来源:Route.java

示例5: processEmoticonsToRegex

import com.google.code.regexp.Pattern; //导入依赖的package包/类
/**
 * Function deprecated since we won't be converting emoticons
 * Processes the Emoji data to emoticon regex
 */
@Deprecated
private static void processEmoticonsToRegex() {
       if(emoticonRegexPattern != null)
           return;

	List<String> emoticons=new ArrayList<>();
	
	for(Emoji e: emojiData) {
		if(e.getEmoticons()!=null) {
			emoticons.addAll(e.getEmoticons());
		}
	}
	
	//List of emotions should be pre-processed to handle instances of subtrings like :-) :-
	//Without this pre-processing, emoticons in a string won't be processed properly
	for(int i=0;i<emoticons.size();i++) {
		for(int j=i+1;j<emoticons.size();j++) {
			String o1=emoticons.get(i);
			String o2=emoticons.get(j);
			
			if(o2.contains(o1)) {
				String temp = o2;
				emoticons.remove(j);
				emoticons.add(i, temp);
			}
		}
	}
	
	
	StringBuilder sb=new StringBuilder();
	for(String emoticon: emoticons) {
		if(sb.length() !=0) {
			sb.append("|");
		}
		sb.append(java.util.regex.Pattern.quote(emoticon));
	}
	
	emoticonRegexPattern = Pattern.compile(sb.toString());
}
 
开发者ID:wax911,项目名称:anitrend-app,代码行数:44,代码来源:EmojiManager.java

示例6: CompiledRoute

import com.google.code.regexp.Pattern; //导入依赖的package包/类
protected CompiledRoute(Parcel in) {
    variables = in.createStringArrayList();
    String regexString = in.readString();
    regex = regexString == null ? null : Pattern.compile(regexString);
    constantUrl = in.readString();
    type = in.readInt();
    weight = in.readInt();
    activityClass = in.readString();
    proxyDestIdentify = in.readString();
    middlewares = in.createStringArrayList();
    anchor = in.readString();
    schemes = in.createStringArrayList();
}
 
开发者ID:mr5,项目名称:android-router,代码行数:14,代码来源:CompiledRoute.java

示例7: compile

import com.google.code.regexp.Pattern; //导入依赖的package包/类
public CompiledRoute compile(Route route) {
    CompiledRoute compiledRoute = new CompiledRoute();

    compiledRoute.weight = route.weight;
    List<String> variables = detectVariables(route);
    compiledRoute.setVariables(variables);
    compiledRoute.setAnchor(route.getAnchor());
    compiledRoute.setType(Route.TYPE_DIRECTLY);
    compiledRoute.setActivityClass(route.getActivityClass().getName());
    if (variables == null || variables.size() < 1) {
        String constantUrl = route.getPath();
        if (route.getAnchor() != null) {
            constantUrl += "#" + route.getAnchor();
        }
        compiledRoute.setConstantUrl(constantUrl);
    } else {
        String regexString = compileRegex(route, variables);
        compiledRoute.setRegex(Pattern.compile(regexString));
    }
    if (route.getProxyDestIdentify() != null) {
        //compiledRoute
        compiledRoute.setType(Route.TYPE_PROXY);
    }
    if (route.getMiddlewares() != null
            && route.getMiddlewares().size() > 0) {
        ArrayList<String> fragmentClassNames = new ArrayList<>();
        for (Class clazz : route.getMiddlewares()) {
            fragmentClassNames.add(clazz.getName());
        }
        compiledRoute.setMiddlewares(fragmentClassNames);
        compiledRoute.setType(Route.TYPE_PROXY);
    }
    return compiledRoute;
}
 
开发者ID:mr5,项目名称:android-router,代码行数:35,代码来源:RouteCompilerImpl.java

示例8: detectVariables

import com.google.code.regexp.Pattern; //导入依赖的package包/类
public static List<String> detectVariables(Route route) {
    Pattern pattern = Pattern.compile("\\{(\\w+)\\}");
    Matcher matcher = pattern.matcher(route.getPath());
    List<String> variables = new ArrayList<>();
    while (matcher.find()) {
        variables.add(matcher.group(1));
    }

    return variables;
}
 
开发者ID:mr5,项目名称:android-router,代码行数:11,代码来源:RouteCompilerImpl.java

示例9: isWhiteIp

import com.google.code.regexp.Pattern; //导入依赖的package包/类
public boolean isWhiteIp(List<String> ips){
 for(String ip:ips){
 	Set<Map.Entry<String, Pattern>> patterns =whiteListPatterns.entrySet();
 	for(Map.Entry<String, Pattern> pattern:patterns){
 		if(pattern.getValue().matcher(ip).find()){
 			return true;
 		}
 	}
 }
 return false;
}
 
开发者ID:DTStack,项目名称:jlogstash-input-plugin,代码行数:12,代码来源:WhiteIpTask.java

示例10: setup

import com.google.code.regexp.Pattern; //导入依赖的package包/类
@Override
public void setup(OperatorContext context)
{
  super.setup(context);
  if (this.regex != null) {
    pattern = Pattern.compile(this.regex);
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:9,代码来源:RegexMatchMapOperator.java

示例11: applyRegexps

import com.google.code.regexp.Pattern; //导入依赖的package包/类
/**
 * Aplicar regexps al mensaje, de todas las regexps enriquequecemos usando
 * la primera regexp que nos devuelva algun resultado.
 *
 * @param message
 * @return map
 */
public Map<String, String> applyRegexps(String message) {
    logger.debug("Message: " + message);


    for (Map.Entry<String, Pattern> entry : regexpMap.entrySet()) {
        logger.debug("Regexp: " + entry.getKey() + " |||| " + entry.getValue());
        Matcher m = entry.getValue().matcher(message);

        if (m.namedGroups().size() > 0) {
            logger.debug("WITH NAMED GROUPS");
            matchesMap.putAll(m.namedGroups());
            break;
        } else {
            logger.debug("WITHOUT NAMED GROUPS");
            // First match is already catched by previous namedGroups() call, so we reset it
            m.reset();
            // Useful for regexps with <key, value> pairs
            while (m.find() && m.groupCount() > 0){
                logger.debug("Group 0: " + m.group(0));
                logger.debug("Group 1: " + m.group(this.regexpKey));
                logger.debug("Group 2: " + m.group(this.regexpValue));
                matchesMap.put(m.group(this.regexpKey), m.group(this.regexpValue));
            }
        }
    }
    return matchesMap;
}
 
开发者ID:keedio,项目名称:flume-enrichment-interceptor-skeleton,代码行数:35,代码来源:RegexpData.java

示例12: testMatchFiles_SINGLE_Regexp

import com.google.code.regexp.Pattern; //导入依赖的package包/类
/**
 * Test of matchFilesRegexp(), of class RegexpData
 */
public void testMatchFiles_SINGLE_Regexp() {
    System.out.println("matchFiles_single_Regexp");

    Path file = Paths.get("src/test/resources/file.log");

    Map<String, String> regexpMap = new HashMap<>();
    Map<String, String> matchesMap = new HashMap<>();

    regexpMap.put("1", "(?<date>\\d{4}-\\d{2}-\\d{2}+)\\s"
            + "(?<time>\\d{2}:\\d{2}:\\d{2}+)\\s"
            + "(?<time-taken>\\d{1}+)\\s");

    try {
        List<String> linesfile = Files.readAllLines(file, Charset.defaultCharset());
        for (String line : linesfile) {
            for (String regexp : regexpMap.values()) {
                Matcher m = Pattern.compile(regexp).matcher(line);
                matchesMap.putAll(m.namedGroups());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println(matchesMap);

}
 
开发者ID:keedio,项目名称:flume-enrichment-interceptor-skeleton,代码行数:31,代码来源:RegexpDataTest.java

示例13: testMatchFiles_SINGLE_Regexp_SEVERAL_lines

import com.google.code.regexp.Pattern; //导入依赖的package包/类
public void testMatchFiles_SINGLE_Regexp_SEVERAL_lines() {
    System.out.println("MatchFiles_SINGLE_Regexp_SEVERAL_lines_Single_file");

    Path file = Paths.get("src/test/resources/file3.log");

    Map<String, String> regexpMap = new HashMap<>();
    Map<String, String> matchesMap = new HashMap<>();

    regexpMap.put("1", "(?<date>\\d{4}-\\d{2}-\\d{2}+)\\s"
            + "(?<time>\\d{2}:\\d{2}:\\d{2}+)\\s"
            + "(?<time-taken>\\d{1}+)\\s");

    try {
        List<String> linesfile = Files.readAllLines(file, Charset.defaultCharset());
        for (String line : linesfile) {
            for (String regexp : regexpMap.values()) {
                Matcher m = Pattern.compile(regexp).matcher(line);
                matchesMap.putAll(m.namedGroups());
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    System.out.println(matchesMap);

}
 
开发者ID:keedio,项目名称:flume-enrichment-interceptor-skeleton,代码行数:28,代码来源:RegexpDataTest.java

示例14: frameChoices

import com.google.code.regexp.Pattern; //导入依赖的package包/类
static String[] frameChoices( int version, Frame fr ) {
  ArrayList<String> al = new ArrayList<>();
  for( java.util.regex.Pattern p : _routes.keySet() ) {
    try {
      Method meth = _routes.get(p)._handler_method;
      Class clz0 = meth.getDeclaringClass();
      Class<Handler> clz = (Class<Handler>)clz0;
      Handler h = clz.newInstance(); // TODO: we don't need to create new instances; handler is stateless
    }
    catch( InstantiationException | IllegalArgumentException | IllegalAccessException ignore ) { }
  }
  return al.toArray(new String[al.size()]);
}
 
开发者ID:kyoren,项目名称:https-github.com-h2oai-h2o-3,代码行数:14,代码来源:RequestServer.java

示例15: processStringWithRegex

import com.google.code.regexp.Pattern; //导入依赖的package包/类
/**
 * Common method used for processing the string to replace with emojis
 * 
 * @param text
 * @param pattern
 * @return
 */
private static String processStringWithRegex(String text, Pattern pattern, int startIndex, boolean recurseEmojify) {
	//System.out.println(text);
	Matcher matcher = pattern.matcher(text);
	StringBuffer sb = new StringBuffer();
	int resetIndex = 0;
	
	if(startIndex > 0) {
		matcher.region(startIndex, text.length());
	} 
	
	while (matcher.find()) {
		
		String emojiCode = matcher.group();
		
		Emoji emoji = getEmoji(emojiCode);
		// replace matched tokens with emojis
		
		if(emoji!=null) {
			matcher.appendReplacement(sb, emoji.getEmoji());
		} else {
			if(htmlSurrogateEntityPattern2.matcher(emojiCode).matches()) {
				String highSurrogate1 = matcher.group("H1");
				String highSurrogate2 = matcher.group("H2");
				String lowSurrogate1 = matcher.group("L1");
				String lowSurrogate2 = matcher.group("L2");
				matcher.appendReplacement(sb, processStringWithRegex(highSurrogate1+highSurrogate2, shortCodeOrHtmlEntityPattern, 0, false));
				
				//basically this handles &#junk1;&#10084;&#65039;&#junk2; scenario
				//verifies if &#junk1;&#10084; or &#junk1; are valid emojis via recursion
				//if not move past &#junk1; and reset the cursor to &#10084;
				if(sb.toString().endsWith(highSurrogate2)) {
					resetIndex = sb.length() - highSurrogate2.length();
				} else {
					resetIndex = sb.length();
				}
				sb.append(lowSurrogate1);
				sb.append(lowSurrogate2);
				break;
			} else if(htmlSurrogateEntityPattern.matcher(emojiCode).matches()) {
				//could be individual html entities assumed as surrogate pair
				String highSurrogate = matcher.group("H");
				String lowSurrogate = matcher.group("L");
				matcher.appendReplacement(sb, processStringWithRegex(highSurrogate, htmlEntityPattern, 0, true));
				resetIndex = sb.length();
				sb.append(lowSurrogate);
				break;
			} else {
				matcher.appendReplacement(sb, emojiCode);
			}
		}

	}
	matcher.appendTail(sb);
	
	//do not recurse emojify when coming here through htmlSurrogateEntityPattern2..so we get a chance to check if the tail
	//is part of a surrogate entity
	if(recurseEmojify && resetIndex > 0) {
		return emojify(sb.toString(), resetIndex);
	}
	return sb.toString();
}
 
开发者ID:wax911,项目名称:anitrend-app,代码行数:69,代码来源:EmojiUtils.java


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