List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:de.snertlab.xdccBee.irc.DccMessageParser.java
public static DccPacket buildDccPacket(String sender, String dccMessage) { DccPacket dccPacket = new DccPacket(); dccPacket.setSender(sender);/* w ww.j ava 2s . c o m*/ String s = cleanMessage(dccMessage); Matcher m = DCC_MESSAGE_PATTER.matcher(s); if (m.find()) { dccPacket.setPacketNr(Integer.parseInt(StringUtils.trim(m.group(1)))); dccPacket.setSize(StringUtils.trim(m.group(2))); String packetName = m.group(3); packetName = StringUtils.trim(packetName); dccPacket.setName(packetName); } return dccPacket; }
From source file:Main.java
/** * Checks if a View matches a certain string and returns the amount of total matches. * /*from w w w .j a v a2 s .c o m*/ * @param regex the regex to match * @param view the view to check * @param uniqueTextViews set of views that have matched * @return number of total matches */ public static int getNumberOfMatches(String regex, TextView view, Set<TextView> uniqueTextViews) { if (view == null) { return uniqueTextViews.size(); } Pattern pattern = null; try { pattern = Pattern.compile(regex); } catch (PatternSyntaxException e) { pattern = Pattern.compile(regex, Pattern.LITERAL); } Matcher matcher = pattern.matcher(view.getText().toString()); if (matcher.find()) { uniqueTextViews.add(view); } if (view.getError() != null) { matcher = pattern.matcher(view.getError().toString()); if (matcher.find()) { uniqueTextViews.add(view); } } if (view.getText().toString().equals("") && view.getHint() != null) { matcher = pattern.matcher(view.getHint().toString()); if (matcher.find()) { uniqueTextViews.add(view); } } return uniqueTextViews.size(); }
From source file:Main.java
public static float getTotalRAM() { RandomAccessFile reader = null; String load = null;//from ww w. j av a2 s . c o m DecimalFormat twoDecimalForm = new DecimalFormat("#.##"); double totRam = 0; float lastValue = 0; try { reader = new RandomAccessFile("/proc/meminfo", "r"); load = reader.readLine(); // Get the Number value from the string Pattern p = Pattern.compile("(\\d+)"); Matcher m = p.matcher(load); String value = ""; while (m.find()) { value = m.group(1); // System.out.println("Ram : " + value); } reader.close(); totRam = Double.parseDouble(value); // totRam = totRam / 1024; float mb = (float) (totRam / 1024.0f); float gb = (float) (totRam / 1048576.0f); float tb = (float) (totRam / 1073741824.0f); lastValue = gb; } catch (IOException ex) { ex.printStackTrace(); } finally { // Streams.close(reader); } return lastValue; }
From source file:com.hygenics.parser.Properties.java
/** * Get a property from a key string// w w w . ja v a 2s . co m * @param k They key containing. * @return The string with the key replaced. */ public static String getProperty(String k) { String rval = k; if (k != null && props != null) { if (k.contains("property:")) { Pattern p = Pattern.compile("property:[^\\s]+"); Matcher m = p.matcher(k); while (m.find()) { rval = rval.replace(m.group(0), System.getProperty(m.group(0).replace("property:", ""))); } return rval; } } return rval; }
From source file:com.uimirror.core.framework.rest.util.WebUtil.java
/** * Find a Domain name from the URL//from ww w.j av a2s . c o m * i.e for http://account.uimirror.com/abc it will extract http://account.uimirror.com * @param url which will be parsed * @return domain from the url */ public static String getURLDomain(String url) { Matcher m = URL_PATTERN.matcher(url); if (m.find()) return m.group(0); return null; }
From source file:Main.java
public static String decodeXML(String inXML) { Pattern p1 = Pattern.compile("<"); Matcher m1 = p1.matcher(inXML); // get a matcher object StringBuffer sb1 = new StringBuffer(); while (m1.find()) { m1.appendReplacement(sb1, "<"); }/*from w w w . j av a2 s. c o m*/ inXML = m1.appendTail(sb1).toString(); Pattern p2 = Pattern.compile(">"); Matcher m2 = p2.matcher(inXML); // get a matcher object StringBuffer sb2 = new StringBuffer(); while (m2.find()) { m2.appendReplacement(sb2, ">"); } String outXML = m2.appendTail(sb2).toString(); return outXML; }
From source file:Main.java
public static String encodeXML(String inXML) { Pattern p1 = Pattern.compile("<"); Matcher m1 = p1.matcher(inXML); // get a matcher object StringBuffer sb1 = new StringBuffer(); while (m1.find()) { m1.appendReplacement(sb1, "<"); }/*from ww w . j a v a 2 s. c o m*/ inXML = m1.appendTail(sb1).toString(); Pattern p2 = Pattern.compile(">"); Matcher m2 = p2.matcher(inXML); // get a matcher object StringBuffer sb2 = new StringBuffer(); while (m2.find()) { m2.appendReplacement(sb2, ">"); } String outXML = m2.appendTail(sb2).toString(); return outXML; }
From source file:com.sap.prd.mobile.ios.mios.XCodeVersionUtil.java
public static DefaultArtifactVersion getVersion(String xCodeVersionString) throws XCodeException { Pattern versionPattern = Pattern.compile("Xcode (\\d+(\\.\\d+)+)", Pattern.CASE_INSENSITIVE); Matcher versionMatcher = versionPattern.matcher(xCodeVersionString); if (versionMatcher.find()) { return new DefaultArtifactVersion(versionMatcher.group(1)); }/*from w ww.java2s . co m*/ throw new XCodeException("Could not get xcodebuild version"); }
From source file:Main.java
public static List<String> getUrlFromBaidu(String htmlStr) { String IMGURL_REG = "objURL\":\"(http://).*?((.jpg)|(.jpeg)|(.png)|(.JPEG))"; Matcher matcher = Pattern.compile(IMGURL_REG).matcher(htmlStr); List<String> listImgUrl = new ArrayList<String>(); while (matcher.find()) { listImgUrl.add(matcher.group().replace("objURL\":\"", "")); }//w w w .java 2s . c o m return listImgUrl; }
From source file:Main.java
/** * replace existing spannable with smiles * // ww w . j a va2 s . c o m * @param context * @param spannable * @return */ public static boolean addSmiles(Context context, Spannable spannable) { boolean hasChanges = false; for (Entry<Pattern, Integer> entry : emoticons.entrySet()) { Matcher matcher = entry.getKey().matcher(spannable); while (matcher.find()) { boolean set = true; for (ImageSpan span : spannable.getSpans(matcher.start(), matcher.end(), ImageSpan.class)) if (spannable.getSpanStart(span) >= matcher.start() && spannable.getSpanEnd(span) <= matcher.end()) spannable.removeSpan(span); else { set = false; break; } if (set) { hasChanges = true; spannable.setSpan(new ImageSpan(context, entry.getValue()), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } } } return hasChanges; }