List of usage examples for java.util.regex Matcher groupCount
public int groupCount()
From source file:com.massabot.codesender.types.GrblSettingMessage.java
private void parse() { Matcher m = MESSAGE_REGEX.matcher(message); if (m.find()) { setting = m.group(1);//from w w w . jav a 2s. c o m value = m.group(2); if (m.groupCount() == 3 && !StringUtils.isEmpty(m.group(3))) { description = m.group(3); } else { String[] lookup = lookups.lookup(setting); if (lookup != null) { units = lookup[2]; description = lookup[3]; shortDescription = lookup[1]; } } } }
From source file:org.auscope.portal.server.gridjob.ScriptParser.java
private List<String> extractStrings(final String regex) { Pattern p = Pattern.compile(regex); Matcher m = p.matcher(scriptText); List<String> result = new ArrayList<String>(); while (m.find()) { if (m.groupCount() >= 1) { result.add(m.group(1));//from w ww . j av a 2 s . c om } } if (result.isEmpty()) { logger.debug("No match for '" + regex + "'."); } return result; }
From source file:info.magnolia.cms.filters.Mapping.java
/** * Determines the index of the first pathInfo character. If the uri does not match any mapping * this method returns -1./*ww w . j av a2 s. c o m*/ */ private int determineMatchingEnd(Matcher matcher) { if (matcher == null) { return -1; } if (matcher.groupCount() > 0) { return matcher.end(1); } return matcher.end(); }
From source file:net.javacoding.jspider.extension.rule.IncreasingRule.java
/** * * * @param context/*from w w w.j av a 2 s . com*/ * @param currentSite * @param url * @return */ @Override public Decision apply(SpiderContext context, Site currentSite, URL url) { URL orgin = url; Object[] pts = null; if (map.containsKey(url.toString())) { // remove ! pts = map.remove(url.toString()); orgin = (URL) pts[0]; } else { String path = url.getPath(); if (this.queryEnable) { if (url.getQuery() != null) { path += "?" + url.getQuery(); } } Matcher mt = pattern.matcher(path); if (mt.matches()) { orgin = url; int size = mt.groupCount(); pts = new Object[size + 2]; pts[0] = url; for (int i = 1; i <= size; i++) { pts[i] = mt.group(i); } } } if (pts != null) { URL find = this.getNexturl(pts, orgin); if (find != null) { log.debug("Increasing page " + find); map.put(find.toString(), pts); context.getAgent().registerEvent(orgin, new URLFoundEvent(context, orgin, find)); } } return new DecisionInternal(DecisionInternal.RULE_ACCEPT); }
From source file:org.talend.license.LicenseRetriver.java
Collection<File> checkout(final String version, final File root, final String url) { try {//from w w w. ja v a2s . c o m return connector.doGet(url, new ResponseHandler<Collection<File>>() { public Collection<File> handleResponse(HttpResponse response) throws ClientProtocolException, IOException { Collection<File> files = new LinkedList<File>(); InputStream stream = response.getEntity().getContent(); ZipInputStream zip = new ZipInputStream(stream); String regex = Configer.getLicenseFile().replaceAll("%version", version); Pattern pattern = Pattern.compile(regex); while (true) { ZipEntry entry = zip.getNextEntry(); if (null == entry) { break; } try { String name = entry.getName(); Matcher matcher = pattern.matcher(name); if (matcher.find()) { int count = matcher.groupCount(); String fname = null; for (int i = 1; i <= count; i++) { fname = matcher.group(i); if (StringUtils.isEmpty(fname)) { continue; } break; } logger.info("found a available license {}", fname); File target = new File(root, fname); if (target.exists()) { files.add(target);// TODO continue; } FileOutputStream fos = new FileOutputStream(target); IOUtils.copy(zip, fos); IOUtils.closeQuietly(fos); files.add(target); } } catch (Exception e) { logger.error(e.getMessage()); } } return files; } }); } catch (Exception e) { logger.error(e.getMessage(), e); } return null; }
From source file:org.apache.flume.sink.hbase.RegexHbaseEventSerializer.java
@Override public List<Row> getActions() throws FlumeException { List<Row> actions = Lists.newArrayList(); byte[] rowKey; Matcher m = inputPattern.matcher(new String(payload)); if (!m.matches()) { return Lists.newArrayList(); }/*from ww w . jav a2s . c o m*/ if (m.groupCount() != colNames.size()) { return Lists.newArrayList(); } try { rowKey = getRowKey(); Put put = new Put(rowKey); for (int i = 0; i < colNames.size(); i++) { put.add(cf, colNames.get(i), m.group(i + 1).getBytes(Charsets.UTF_8)); } actions.add(put); } catch (Exception e) { throw new FlumeException("Could not get row key!", e); } return actions; }
From source file:horriblev3.Cloudflare.java
private String regex(String text, String regex) { System.out.println("TEXT: " + text + "\n" + "REGEX: " + regex); Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(text); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); }/*from w w w. ja va 2s. c om*/ if (matcher.groupCount() >= 1) { return matcher.group(1); } } return null; }
From source file:org.cunframework.sc.map4j.core.providers.google.GoogleMapProviderBase.java
@Override public void OnInitialized() { if (!init && TryCorrectVersion) { String url = String.format( "https://maps.%1$s/maps/api/js?client=google-maps-lite&libraries=search&language=en&region=", ServerAPIs);/*from www. j a va 2 s . co m*/ String html = ""; html = GetContentUsingHttp(url); if (!StringUtils.isBlank(html)) { Pattern reg = Pattern.compile(String.format("https?://mts?\\d.%1$s/vt\\?lyrs=m@(\\d*)", Server)); Matcher mat = reg.matcher(html); if (mat.find()) { int count = mat.groupCount(); if (count > 0) { String ver = String.format("m@%1$s", mat.group(1)); String old = GMapProviders.Instance.GoogleMap.Version; GMapProviders.Instance.GoogleMap.Version = ver; GMapProviders.Instance.GoogleChinaMap.Version = ver; } } reg = Pattern.compile(String.format("https?://mts?\\d.%1$s/vt\\?lyrs=h@(\\d*)", Server)); mat = reg.matcher(html); if (mat.find()) { int count = mat.groupCount(); if (count > 0) { String ver = String.format("h@%1$s", mat.group(1)); String old = GMapProviders.Instance.GoogleHybridMap.Version; GMapProviders.Instance.GoogleHybridMap.Version = ver; GMapProviders.Instance.GoogleChinaHybridMap.Version = ver; } } reg = Pattern.compile(String.format("https?://khms?\\d.%1$s/kh\\?v=(\\d*)", Server)); mat = reg.matcher(html); if (mat.find()) { int count = mat.groupCount(); if (count > 0) { String ver = mat.group(1); String old = GMapProviders.Instance.GoogleSatelliteMap.Version; GMapProviders.Instance.GoogleSatelliteMap.Version = ver; GMapProviders.Instance.GoogleChinaSatelliteMap.Version = "s@" + ver; } } reg = Pattern.compile(String.format("https?://mts?\\d.%1$s/vt\\?lyrs=t@(\\d*),r@(\\d*)", Server)); mat = reg.matcher(html); if (mat.find()) { int count = mat.groupCount(); if (count > 1) { String ver = String.format("t@%1$s,r@%2$s", mat.group(1), mat.group(2)); String old = GMapProviders.Instance.GoogleTerrainMap.Version; GMapProviders.Instance.GoogleTerrainMap.Version = ver; GMapProviders.Instance.GoogleChinaTerrainMap.Version = ver; } } } init = true; } }