List of usage examples for java.util.regex Matcher find
public boolean find()
From source file:Main.java
public static String getActionOfExpression(String expression) { // pattern for actions Pattern actionPattern = Pattern .compile("^([\\w\\W&&[^/\\[\\]]]+)?(\\[[\\w\\W&&[^\\[\\]]]+\\])?(/[\\w\\W]+)$"); Matcher actionMatcher = actionPattern.matcher(expression); if (actionMatcher.find() && (actionMatcher.group().length() == expression.length())) { String action = expression.substring(expression.lastIndexOf("/") + 1); return action; }//from www .ja v a 2s.c o m return null; }
From source file:Main.java
public static Integer parseInt(String value) { if (value == null) { return 0; }/* w w w . j a v a 2 s.c o m*/ Integer val = 0; try { Matcher matcher = pattern.matcher(value); if (matcher.find()) { String num = matcher.group(0); val = Integer.parseInt(num); } } catch (Exception e) { e.printStackTrace(); } return val; }
From source file:Main.java
public static String getContentMathML(String latexMLResponse) { String CML_REGEX = "<annotation-xml.*MWS-Query\">(.*)<.annotation-xml>"; Pattern pattern = Pattern.compile(CML_REGEX, Pattern.DOTALL); try {//ww w. j a v a 2 s .c om JSONObject latexMLJSON = new JSONObject(latexMLResponse); String math = latexMLJSON.getString("result"); Matcher matcher = pattern.matcher(math); if (matcher.find()) { return matcher.group(1); } } catch (JSONException e) { e.printStackTrace(); } return null; }
From source file:Main.java
/** * Extracts ID from the video url/*from w ww. j a va2 s . c om*/ * @param youtubeUrl the video url * @return the ID of the video */ public static String extractYouTubeVideoId(String youtubeUrl) { String pattern = "(?<=youtu.be/|watch\\?v=|/videos/|embed\\/)[^#\\&\\?]*"; Pattern compiledPattern = Pattern.compile(pattern); Matcher matcher = compiledPattern.matcher(youtubeUrl); if (matcher.find()) { return matcher.group(); } else { return "H7B1NhceHEg"; } }
From source file:Main.java
public static CharSequence scaleEmotions(String text) { SpannableString spannableString = new SpannableString(text); for (String emotion : emotions) { Pattern pattern = Pattern.compile(emotion); Matcher matcher = pattern.matcher(text); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); spannableString.setSpan(new RelativeSizeSpan(1.2f), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }//from w w w . j a va 2s . co m } return spannableString; }
From source file:Main.java
private static String getFileNameByUrl(String url) { // TODO Auto-generated method stub Pattern p = Pattern.compile("\\w+"); Matcher m = p.matcher(url); String filename = ""; while (m.find()) { String str = m.group();//from ww w.j av a 2 s .co m filename = str; } return filename; }
From source file:MatchDuplicateWords.java
public static boolean hasDuplicate(String phrase) { boolean retval = false; String duplicatePattern = "\\b(\\w+) \\1\\b"; Pattern p = null;// ww w .j a va 2 s. co m try { p = Pattern.compile(duplicatePattern); } catch (PatternSyntaxException pex) { pex.printStackTrace(); System.exit(0); } int matches = 0; Matcher m = p.matcher(phrase); String val = null; while (m.find()) { retval = true; val = ":" + m.group() + ":"; System.out.println(val); matches++; } String msg = " NO MATCH: pattern:" + phrase + "\r\n regex: " + duplicatePattern; if (retval) { msg = " MATCH : pattern:" + phrase + "\r\n regex: " + duplicatePattern; } System.out.println(msg + "\r\n"); return retval; }
From source file:Main.java
public static String getFirstMatch(String html, String pattern) { Pattern p = Pattern.compile(pattern); Matcher m = p.matcher(html); String result = ""; while (m.find()) { result = m.group(1);/* w w w .j a v a 2 s . co m*/ break; } return result; }
From source file:Main.java
public static String regexText(String source, String regex, int group) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(source); boolean b = matcher.find(); if (b) {//from w w w .j a v a2s . co m return matcher.group(group); } return null; }
From source file:Main.java
public static String searchAndReturn(String source, String regex) { Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(source); boolean b = matcher.find(); if (b) {//from w w w . j a va 2 s. co m return source.substring(matcher.start(), matcher.end()); } return null; }