List of usage examples for java.util.regex Matcher group
public String group(String name)
From source file:Main.java
public static String[] getTagDataArray(String xmlStr, String xmlRoot) { List<String> data = new ArrayList<String>(); Matcher m; m = Pattern.compile("<" + xmlRoot + ">(.*?)</" + xmlRoot + ">", Pattern.MULTILINE | Pattern.DOTALL) .matcher(xmlStr);//from w w w . j a va2s . c o m while (m.find()) { data.add(xmlToText(m.group(1))); } return data.toArray(new String[data.size()]); }
From source file:com.magnet.plugin.r2m.helpers.UrlParser.java
public static ParsedUrl parseUrl(String url) { List<PathPart> pathParts = new ArrayList<PathPart>(); List<Query> queries = new ArrayList<Query>(); ParsedUrl parsedUrl;/*from w w w .j av a 2 s. c om*/ String base; try { URL aURL = new URL(url); base = aURL.getAuthority(); String protocol = aURL.getProtocol(); parsedUrl = new ParsedUrl(); parsedUrl.setPathWithEndingSlash(aURL.getPath().endsWith("/")); parsedUrl.setBaseUrl(protocol + "://" + base); List<NameValuePair> pairs = URLEncodedUtils.parse(aURL.getQuery(), Charset.defaultCharset()); for (NameValuePair pair : pairs) { Query query = new Query(pair.getName(), pair.getValue()); queries.add(query); } parsedUrl.setQueries(queries); String[] pathStrings = aURL.getPath().split("/"); for (String pathPart : pathStrings) { Matcher m = PATH_PARAM_PATTERN.matcher(pathPart); if (m.find()) { String paramDef = m.group(1); String[] paramParts = paramDef.split(":"); if (paramParts.length > 1) { pathParts.add(new PathPart(paramParts[1].trim(), paramParts[0].trim())); } else { pathParts.add(new PathPart(paramParts[0].trim())); } } else { if (!pathPart.isEmpty()) { pathParts.add(new PathPart(pathPart)); } } } parsedUrl.setPathParts(pathParts); } catch (Exception ex) { Logger.error(UrlParser.class, R2MMessages.getMessage("CANNOT_PARSE_URL", url)); return null; } return parsedUrl; }
From source file:ca.weblite.xmlvm.ConstantPoolHelper.java
public static void removeConstantPoolDependencies(Map<Integer, Constant> constantPool, File file) throws IOException { String strPattern = "xmlvm_create_java_string_from_pool\\((\\d+)\\)"; Pattern regex = Pattern.compile(strPattern); List<String> lines = FileUtils.readLines(file); List<String> out = new ArrayList<String>(); boolean changed = false; for (String line : lines) { if (line.indexOf("xmlvm_create_java_string_from_pool") != -1) { Matcher m = regex.matcher(line); if (m.find()) { String idStr = m.group(1); Constant theConstant = constantPool.get(Integer.parseInt(idStr)); String strVal = theConstant.data; int len = theConstant.len; if (strVal == null) { throw new RuntimeException("Constant pool does not contain string id " + idStr); }//from ww w. j av a2 s.c o m changed = true; line = line.replaceAll(strPattern, "xmlvm_create_java_string_from_char_array((JAVA_OBJECT)" + strVal + "," + len + ")"); } } out.add(line); } if (changed) { FileUtils.writeLines(file, out); } }
From source file:emily.util.YTUtil.java
/** * Extracts the playlistcode from a yt url * * @param url the url/*from w ww . j ava2 s . co m*/ * @return playlistcode || null if not found */ public static String getPlayListCode(String url) { Matcher matcher = yturl.matcher(url); if (matcher.find()) { if (matcher.groupCount() == 2) { return matcher.group(2); } } return null; }
From source file:io.viewserver.core.Utils.java
public static String replaceSystemTokens(String inputString) { String result = inputString;//from w w w . j a v a 2 s. c o m Pattern pattern = Pattern.compile("%([^%]+)%"); Matcher matcher = pattern.matcher(inputString); while (true) { boolean found = false; while (matcher.find()) { found = true; String token = matcher.group(1); String value = Configuration.getString(token); if (value != null) { boolean encrypted = Configuration.getBoolean(String.format("%s[@%s]", token, PARSE_KEY), false); if (encrypted) { value = parse(value); } result = result.replace(matcher.group(0), value); } } if (!found) { break; } matcher.reset(result); } //only replace single backslashes with double backslashes return result.replaceAll(Matcher.quoteReplacement("(?<!\\)\\(?![\\\"\'])"), Matcher.quoteReplacement("\\\\")); }
From source file:Main.java
/** * Validates and processes the given Url * @param url The given Url to process * @return Pre-process Url as string */ public static String cleanUrl(StringBuilder url) { //ensure that the urls are absolute Pattern pattern = Pattern.compile("^(https?://[^/]+)"); Matcher matcher = pattern.matcher(url); if (!matcher.find()) throw new IllegalArgumentException("Invalid Url format."); //get the http protocol match String protocol = matcher.group(1); //remove redundant forward slashes String query = url.substring(protocol.length()); query = query.replaceAll("//+", "/"); //return process url return protocol.concat(query); }
From source file:com.datumbox.framework.utilities.text.cleaners.HTMLCleaner.java
public static String extractTitle(String text) { Matcher m = TITLE_PATTERN.matcher(text); if (m.find()) { return clear(m.group(0)); }/*from ww w .java2 s . c o m*/ return null; }
From source file:org.brnvrn.Main.java
private static boolean parseComment(Tool tool, Comment comment) { String field = comment.getData(); if (field == null) return false; if (field.contains("erified")) { Matcher m = p.matcher(field); if (m.find()) tool.setVerified(m.group(0)); } else if (field.contains("pdate")) { Matcher m = p.matcher(field); if (m.find()) tool.setLast_update(m.group(0)); } else//from w w w . j av a 2 s . c o m System.out.println(" # Unknown comment " + field); return true; }
From source file:com.mirth.connect.connectors.jdbc.JdbcUtils.java
/** * Parse the given statement filling the parameter list and return the ready to use statement. * /*from w ww . ja va 2 s .co m*/ * @param statement * @param params * List that will contain the parameters found in the statement * @return The parsed statement */ public static String extractParameters(String statement, List<String> params) { if (statement == null) { return null; } Pattern p = Pattern.compile("\\$\\{([^\\}]*)\\}"); Matcher m = p.matcher(statement); StringBuffer sb = new StringBuffer(); while (m.find()) { String key = m.group(0); m.appendReplacement(sb, "?"); params.add(key); } m.appendTail(sb); return sb.toString(); }
From source file:com.github.jjYBdx4IL.utils.fma.FMAClient.java
public static String parseDownloadUrl(String trackUrl) throws IOException { byte[] data = cache.retrieve(trackUrl, 3600 * 1000L); LOG.debug("track url: " + trackUrl); String page = new String(data, "UTF-8"); LOG.debug("track url page content: " + page); Matcher m = DL_URL_PAT.matcher(page); String url = null;//from ww w. ja v a2 s. c o m if (m.find()) { url = m.group(1); } LOG.debug("download url: " + url); return url; }