List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
public static String getAccountType(Context context, long id, String name) { try {/*from ww w.j a v a 2 s . co m*/ Cursor cur = context.getContentResolver().query(ContactsContract.RawContacts.CONTENT_URI, new String[] { ContactsContract.RawContacts.ACCOUNT_TYPE, ContactsContract.RawContacts.ACCOUNT_NAME }, ContactsContract.RawContacts.CONTACT_ID + " = ?", new String[] { String.valueOf(id) }, null); if (cur != null) { String str = ""; while (cur.moveToNext()) { str += cur.getString(cur.getColumnIndex(ContactsContract.RawContacts.ACCOUNT_TYPE)); } // Log.v("getAccountType", name+" => "+str); cur.close(); Matcher m = accountTypePattern.matcher(str); String last = ""; while (m.find()) { last = m.group(1); } return last; } } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:io.dockstore.webservice.helpers.SourceCodeRepoFactory.java
/** * Parse Git URL to retrieve source, username and repository name. * * @param url//from w w w . jav a2 s . c o m * @return a map with keys: Source, Username, Repository */ public static Map<String, String> parseGitUrl(String url) { Pattern p = Pattern.compile("git\\@(\\S+):(\\S+)/(\\S+)\\.git"); Matcher m = p.matcher(url); if (!m.find()) { LOG.info("Cannot parse url: " + url); return null; } // These correspond to the positions of the pattern matcher final int sourceIndex = 1; final int usernameIndex = 2; final int reponameIndex = 3; String source = m.group(sourceIndex); String gitUsername = m.group(usernameIndex); String gitRepository = m.group(reponameIndex); LOG.info("Source: " + source); LOG.info("Username: " + gitUsername); LOG.info("Repository: " + gitRepository); Map<String, String> map = new HashMap<>(); map.put("Source", source); map.put("Username", gitUsername); map.put("Repository", gitRepository); return map; }
From source file:Main.java
private static void killprocessNormal(String proc, int killMethod) { try {//from w w w. j a v a 2s . com ArrayList<String> pid_list = new ArrayList<String>(); ProcessBuilder execBuilder = null; execBuilder = new ProcessBuilder("sh", "-c", "ps |grep " + proc); execBuilder.redirectErrorStream(true); Process exec = null; exec = execBuilder.start(); InputStream is = exec.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line = ""; while ((line = reader.readLine()) != null) { String regEx = "\\s[0-9][0-9]*\\s"; Pattern pat = Pattern.compile(regEx); Matcher mat = pat.matcher(line); if (mat.find()) { String temp = mat.group(); temp = temp.replaceAll("\\s", ""); pid_list.add(temp); } } for (int i = 0; i < pid_list.size(); i++) { execBuilder = new ProcessBuilder("su", "-c", "kill", "-" + killMethod, pid_list.get(i)); exec = null; exec = execBuilder.start(); execBuilder = new ProcessBuilder("su", "-c", "kill" + " -" + killMethod + " " + pid_list.get(i)); exec = null; exec = execBuilder.start(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
public static String getEmbeddedChecksum(CharSequence string) { Matcher matcher = EMBEDDED_CHECKSUM.matcher(string); String embeddedChecksum = null; // get last match while (matcher.find()) { embeddedChecksum = matcher.group(); }/* www . ja v a2s .c o m*/ return embeddedChecksum; }
From source file:com.castlemock.core.basis.utility.parser.TextParser.java
/** * The parse method is responsible for parsing a provided text and transform the text * with the help of {@link Expression}. {@link Expression} in the texts will be transformed * and replaced with new values. The transformed text will be returned. * @param text The provided text that will be transformed. * @return A transformed text. All expressions will be replaced by new values. * Please note that the same text will be returned if no expressions * were found in the provided text. *///from w w w .j a v a2s .com public static String parse(final String text) { String output = text; Pattern pattern = Pattern.compile("(?=\\$\\{)(.*?)\\}"); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String match = matcher.group(); ExpressionInput expressionInput = ExpressionInputParser.parse(match); Expression expression = EXPRESSIONS.get(expressionInput.getName()); if (expression == null) { LOGGER.error("Unable to parse the following expression: " + expressionInput.getName()); continue; } String expressionResult = expression.transform(expressionInput); output = StringUtils.replaceOnce(output, match, expressionResult); } return output; }
From source file:com.romeikat.datamessie.core.base.ui.component.DocumentsFilter.java
private static List<Long> extractDocumentIds(final String text) { final List<Long> documentIds = new LinkedList<Long>(); if (text != null) { final Pattern p = Pattern.compile("\\d+"); final Matcher m = p.matcher(text); while (m.find()) { final String document = m.group(); final long documentId = Long.parseLong(document); documentIds.add(documentId); }/* ww w. j ava 2 s . c om*/ } return documentIds; }
From source file:com.uimirror.core.framework.rest.util.WebUtil.java
/** * Checks if the URL is a local host//from w ww . j av a2s .com * @param url which will be parsed * @return <code>true</code> if url is localhost */ public static boolean isLoaclHostURL(String url) { Matcher m = LOCAL_HOST_PATTERN.matcher(url); return m.find(); }
From source file:io.github.carlomicieli.footballdb.starter.mapping.Height.java
private static Optional<Height> extractValue(String value, Pattern p) { Matcher m = p.matcher(value); if (m.find()) { int f = Integer.parseInt(m.group(1)); int i = Integer.parseInt(m.group(2)); return Optional.ofNullable(new Height(f, i)); }// w ww. j ava 2s . c o m return Optional.empty(); }
From source file:io.amient.examples.wikipedia.WikipediaMessage.java
private static WikipediaMessage parseText(String raw) { Pattern p = Pattern.compile("\\[\\[(.*)\\]\\]\\s(.*)\\s(.*)\\s\\*\\s(.*)\\s\\*\\s\\(\\+?(.\\d*)\\)\\s(.*)"); Matcher m = p.matcher(raw); if (!m.find()) { throw new IllegalArgumentException("Could not parse message: " + raw); } else if (m.groupCount() != 6) { throw new IllegalArgumentException("Unexpected parser group count: " + m.groupCount()); } else {/*from w w w . j av a 2 s .c o m*/ WikipediaMessage result = new WikipediaMessage(); result.title = m.group(1); String flags = m.group(2); result.diffUrl = m.group(3); result.user = m.group(4); result.byteDiff = Integer.parseInt(m.group(5)); result.summary = m.group(6); result.isNew = flags.contains("N"); result.isMinor = flags.contains("M"); result.isUnpatrolled = flags.contains("!"); result.isBotEdit = flags.contains("B"); result.type = result.title.startsWith("Special:") ? Type.SPECIAL : (result.title.startsWith("Talk:") ? Type.TALK : Type.EDIT); return result; } }
From source file:fitnesse.responders.files.UploadResponder.java
public static String makeRelativeFilename(String name) { Matcher match = filenamePattern.matcher(name); if (match.find()) return match.group(2); else/*from w ww. j a va 2 s.c om*/ return name; }