private void addFileToMap(Matcher matcher, Path file, boolean sawBase, Map<Integer, BucketTracker> splitToBucketMap) { if (!matcher.find()) { String msg = "Found a non-bucket file that we thought matched the bucket pattern! " + file.toString() + " Matcher=" + matcher.toString(); LOG.error(msg); //following matcher.group() would fail anyway and we don't want to skip files since that //may be a data loss scenario throw new IllegalArgumentException(msg); } int bucketNum = Integer.parseInt(matcher.group()); BucketTracker bt = splitToBucketMap.get(bucketNum); if (bt == null) { bt = new BucketTracker(); splitToBucketMap.put(bucketNum, bt); } LOG.debug("Adding " + file.toString() + " to list of files for splits"); bt.buckets.add(file); bt.sawBase |= sawBase; }
private void addFileToMap(Matcher matcher, Path file, boolean sawBase, Map<Integer, BucketTracker> splitToBucketMap) { if (!matcher.find()) { LOG.warn("Found a non-bucket file that we thought matched the bucket pattern! " + file.toString() + " Matcher=" + matcher.toString()); } int bucketNum = Integer.parseInt(matcher.group()); BucketTracker bt = splitToBucketMap.get(bucketNum); if (bt == null) { bt = new BucketTracker(); splitToBucketMap.put(bucketNum, bt); } LOG.debug("Adding " + file.toString() + " to list of files for splits"); bt.buckets.add(file); bt.sawBase |= sawBase; }
public String toString() { return matcher.toString(); } }
public String toString() { return matcher.toString(); }
public String toString() { return matcher.toString(); } }
public String toString() { return "ReaderMatcher: " + matcher.toString(); }
public String toString() { return matcher.toString(); }
public String toString() { return String.format("TimeLimitedMatcher of [%s]", matcher.toString()); }
protected boolean execPattern(final String input) { Matcher matcher = pattern.matcher(input); try { return matcher.matches(); } catch (Throwable e) { log.error("Error matching pattern " + matcher.toString() + " with value " + input, e); } return false; }
public class Main { private static final String REGEX = "\\[([^\\]]+)"; private static final String INPUT = "10:11:22 [UTP][ROX][ID:32424][APP STR]"; private static Pattern pattern; private static Matcher matcher; public static void main(String[] args) { Pattern pattern = Pattern.compile(REGEX); Matcher matcher = pattern.matcher(INPUT); while (matcher.find()) { System.out.println(matcher.toString()); } } }
import java.util.regex.Matcher; import java.util.regex.Pattern; public class TCPChat { static public void main(String[] args) { String url = "<img src=\"http://stackoverflow.com/a/b/c/d/someimage.jpg\">"; Pattern p = Pattern.compile("<img src=\"http://stackoverflow.com/.*jpg\">"); // Create a matcher with an input string Matcher m = p.matcher(url); while (m.find()) { String s = m.toString(); System.out.println(s); } } }
Matcher base = Pattern.compile("\\bred\\b|\\bgreen\\b|\\bblue\\b|[+()]{1}").matcher(input.trim()); while (!base.hitEnd()) { if (base.find()) { String s = base.group(); System.out.println("Found: " + s); output += String.format(" %s", s); } } if (output.isEmpty()) { throw new IllegalArgumentException("Invalid input no matching tokens found! " + base.toString()); }
/** * Recherhce l'ensemble des clé dans le template. * @param templateText le template à traiter. * @return la map des clés trouvé. */ protected Map<String, Set<String>> findKey(String templateText) { Map<String, Set<String>> result = new HashMap<String, Set<String>>(); //Pattern keyTemplate = Pattern.compile(START_PATTERN + "(.*?)" + END_PATTERN); Pattern keyTemplate = Pattern.compile(FIND_PATTERN); Matcher tagmatch = keyTemplate.matcher(templateText); LOGGER.debug("Matcher généré: {} - {}", tagmatch.toString(), templateText); //LOGGER.debug("find: {}", tagmatch.find()); while (tagmatch.find()) { LOGGER.debug("groupe: {}", tagmatch.group(2)); String key = StringUtils.substringBefore(tagmatch.group(2), SEPARATOR); String ext = StringUtils.substringAfter(tagmatch.group(2), SEPARATOR); if (result.containsKey(key)) { ((HashSet) result.get(key)).add(ext); } else { Set<String> set = new HashSet<String>(); set.add(ext); result.put(key, set); } } LOGGER.debug("End find key."); return result; }
/** Construct a TaskID object from given string * @return constructed TaskID object or null if the given String is null * @throws IllegalArgumentException if the given string is malformed */ public static TaskID forName(String str) throws IllegalArgumentException { if(str == null) return null; Matcher m = taskIdPattern.matcher(str); if (m.matches()) { return new org.apache.hadoop.mapred.TaskID(m.group(1), Integer.parseInt(m.group(2)), CharTaskTypeMaps.getTaskType(m.group(3).charAt(0)), Integer.parseInt(m.group(4))); } String exceptionMsg = "TaskId string : " + str + " is not properly formed" + "\nReason: " + m.toString(); throw new IllegalArgumentException(exceptionMsg); } /**
log.error("group count on function finder regex is not as expected"); if (log.isDebugEnabled()) { log.error("functionMatcher: " + functionMatcher.toString());
log.error("group count on function finder regex is not as expected"); if (log.isDebugEnabled()) { log.error("functionMatcher: " + functionMatcher.toString());
log.error("group count on variable finder regex is not as expected"); if (log.isDebugEnabled()) { log.error("variableMatcher: " + variableMatcher.toString());
log.error("group count on backref finder regex is not as expected"); if (log.isDebugEnabled()) { log.error("varMatcher: " + varMatcher.toString());
log.error("group count on backref finder regex is not as expected"); if (log.isDebugEnabled()) { log.error("varMatcher: " + varMatcher.toString());
log.error("group count on backref finder regex is not as expected"); if (log.isDebugEnabled()) { log.error("backRefMatcher: " + backRefMatcher.toString());