List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
public static List<String> findFileInCardText(String cardText, String[] fileExtensions) { List<String> filesFound = new ArrayList<String>(); if (fileExtensions == null || fileExtensions.length == 0) { assert false : "fileExtensions should never be empty or null"; return filesFound; }//from w w w. j a va2s . c om StringBuilder extensionPatternBuilder = new StringBuilder(); // File name pattern extensionPatternBuilder.append("[A-Za-z0-9_-]+"); // extension pattern extensionPatternBuilder.append("\\.("); for (int i = 0; i < fileExtensions.length; i++) { // The format is ext1|ext2|ext3 so the first occurance // does not have a |. if (i == 0) { extensionPatternBuilder.append(fileExtensions[i]); } else { extensionPatternBuilder.append("|" + fileExtensions[i]); } } extensionPatternBuilder.append(")"); // The regex here should match the file types in SUPPORTED_AUDIO_FILE_TYPE Pattern p = Pattern.compile(extensionPatternBuilder.toString()); Matcher m = p.matcher(cardText); while (m.find()) { filesFound.add(m.group()); } return filesFound; }
From source file:Main.java
public static String fiterHtmlTag(String str, String tag) { String regxp = "<\\s*" + tag + "\\s+([^>]*)\\s*>"; Pattern pattern = Pattern.compile(regxp); Matcher matcher = pattern.matcher(str); StringBuffer sb = new StringBuffer(); boolean result1 = matcher.find(); while (result1) { matcher.appendReplacement(sb, ""); result1 = matcher.find();//ww w . j a v a 2s . co m } matcher.appendTail(sb); return sb.toString(); }
From source file:Main.java
public static SpannableString toSpannableString(Context context, String text, SpannableString spannableString) { int start = 0; Pattern pattern = Pattern.compile("\\\\ue[a-z0-9]{3}", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(text); while (matcher.find()) { String faceText = matcher.group(); String key = faceText.substring(1); BitmapFactory.Options options = new BitmapFactory.Options(); // options.inSampleSize = 2; Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), context.getResources().getIdentifier(key, "drawable", context.getPackageName()), options); ImageSpan imageSpan = new ImageSpan(context, bitmap); int startIndex = text.indexOf(faceText, start); int endIndex = startIndex + faceText.length(); if (startIndex >= 0) spannableString.setSpan(imageSpan, startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); start = (endIndex - 1);/* w ww . j av a 2s. c o m*/ } return spannableString; }
From source file:com.assemblade.opendj.acis.CompositeSubject.java
public static Subject parse(Subject left, String text) { Matcher compositeMatcher = compositePattern.matcher(text); if (compositeMatcher.find()) { String operand = compositeMatcher.group(1).trim(); String right = compositeMatcher.group(2); if (StringUtils.isNotEmpty(operand) && (operand.equalsIgnoreCase("AND") || operand.equalsIgnoreCase("OR"))) { return new CompositeSubject(left, Subject.parse(right), operand); }/* w ww . ja v a 2s . co m*/ } return null; }
From source file:Main.java
public static String IntegerToString(String str) { Pattern p = Pattern.compile("&#[0-9]{5};"); Matcher m = p.matcher(str); String g = ""; String num = ""; char c = 0;/*from w w w . j a va2s . co m*/ while (m.find()) { g = m.group(); num = g.substring(2, 7); c = (char) (Integer.parseInt(num)); str = str.replace(g, "" + c); } return str; }
From source file:Main.java
/** * Get the objid from an URI/Fedora identifier, e.g. from <info:fedora/escidoc:1><br/> If the provided value * does not match the expected pattern, it is returned as provided. Otherwise, the objid is extracted from it and * returned./* w w w. ja va2 s . c om*/ * * @param uri The value to get the objid from * @return Returns the extracted objid or the provided value. */ public static String getIdFromURI(final String uri) { if (uri == null) { return null; } final Matcher matcher = PATTERN_GET_ID_FROM_URI_OR_FEDORA_ID.matcher(uri); return matcher.find() ? matcher.group(1) : uri; }
From source file:Main.java
private static String getAaptResult(String sdkPath, String apkPath, final Pattern pattern) { try {/*from www .j a va 2s . co m*/ final File apkFile = new File(apkPath); final ByteArrayOutputStream aaptOutput = new ByteArrayOutputStream(); final String command = getAaptDumpBadgingCommand(sdkPath, apkFile.getName()); Process process = Runtime.getRuntime().exec(command, null, apkFile.getParentFile()); InputStream inputStream = process.getInputStream(); for (int last = inputStream.read(); last != -1; last = inputStream.read()) { aaptOutput.write(last); } String packageId = ""; final String aaptResult = aaptOutput.toString(); if (aaptResult.length() > 0) { final Matcher matcher = pattern.matcher(aaptResult); if (matcher.find()) { packageId = matcher.group(1); } } return packageId; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static String fixCharCode(String wholeFile) { long millis = System.currentTimeMillis(); Matcher mat = CHAR_CODE_PATTERN.matcher(wholeFile); StringBuffer sb = new StringBuffer(); while (mat.find()) { // System.gc(); mat.appendReplacement(sb, ((char) Integer.parseInt(mat.group(1)) + "")); }//from w w w . j av a 2 s. co m mat.appendTail(sb); Log.d("fix char code time: ", "" + (System.currentTimeMillis() - millis)); return sb.toString(); }
From source file:Main.java
/** * Escape some special character as HTML escape sequence. * //from w w w .ja v a2 s . co m * @param text Text to be displayed using WebView. * @return Text correctly escaped. */ public static String escapeCharacterToDisplay(String text) { Pattern pattern = PLAIN_TEXT_TO_ESCAPE; Matcher match = pattern.matcher(text); if (match.find()) { StringBuilder out = new StringBuilder(); int end = 0; do { int start = match.start(); out.append(text.substring(end, start)); end = match.end(); int c = text.codePointAt(start); if (c == ' ') { // Escape successive spaces into series of " ". for (int i = 1, n = end - start; i < n; ++i) { out.append(" "); } out.append(' '); } else if (c == '\r' || c == '\n') { out.append("<br>"); } else if (c == '<') { out.append("<"); } else if (c == '>') { out.append(">"); } else if (c == '&') { out.append("&"); } } while (match.find()); out.append(text.substring(end)); text = out.toString(); } return text; }
From source file:Main.java
private static String renderEmail(String bodyHtml) { StringBuffer bodyStringBuffer = new StringBuffer(); Matcher matcherEmailContent = patternTagTitle.matcher(bodyHtml); while (matcherEmailContent.find()) { String processContent = matcherEmailContent.group(1); String htmlContent = matcherEmailContent.group(2); if (htmlContent.equalsIgnoreCase("</script>") || htmlContent.equalsIgnoreCase("</a>")) { matcherEmailContent.appendReplacement(bodyStringBuffer, processContent + htmlContent); } else {//from w w w. j a v a 2 s. com String emailContentHasProcessed = makeEmailHerf(processContent); matcherEmailContent.appendReplacement(bodyStringBuffer, emailContentHasProcessed + htmlContent); } } matcherEmailContent.appendTail(bodyStringBuffer); return bodyStringBuffer.toString(); }