List of usage examples for java.util.regex Matcher group
public String group()
From source file:edu.ku.brc.web.ParsePaleo.java
/** * @param args// w w w . jav a 2 s .com */ public static void main(String[] args) { if (true) { ParsePaleo pp = new ParsePaleo(); pp.processAll(); return; } try { HashSet<String> set = new HashSet<String>(); for (String line : FileUtils.readLines(new File("/Users/rods/Downloads/ages.txt"))) { //Pattern p = Pattern.compile("\"([^\"\\]*(\\.[^\"\\]*)*)\"|\'([^\'\\]*(\\.[^\'\\]*)*)\'"); //Pattern p = Pattern.compile("\"([^\"]*)\"|(\\S+)"); Pattern p = Pattern.compile("\"([^\"]*)\""); Matcher m = p.matcher(line); //List<String> animals = new ArrayList()<String>(); while (m.find()) { //System.out.println(m.group()); set.add(replace(m.group(), "\"", "")); //animals.add(m.group()); } } for (String str : set) { System.out.println(str); } } catch (Exception ex) { ex.printStackTrace(); } }
From source file:Main.java
public static void main(String[] args) { Pattern pattern = null;/*from w ww . ja v a 2 s . c o m*/ Matcher matcher = null; Console console = System.console(); while (true) { try { pattern = Pattern.compile(console.readLine("%nEnter your regex: ")); matcher = pattern.matcher(console.readLine("Enter input string to search: ")); } catch (PatternSyntaxException pse) { console.format("There is a problem with the regular expression!%n"); console.format("The pattern in question is: %s%n", pse.getPattern()); console.format("The description is: %s%n", pse.getDescription()); console.format("The message is: %s%n", pse.getMessage()); console.format("The index is: %s%n", pse.getIndex()); System.exit(0); } boolean found = false; while (matcher.find()) { console.format("I found the text \"%s\" starting at " + "index %d and ending at index %d.%n", matcher.group(), matcher.start(), matcher.end()); found = true; } if (!found) { console.format("No match found.%n"); } } }
From source file:Main.java
public static String find(String patternStr, CharSequence input) { Pattern pattern = Pattern.compile(patternStr); Matcher matcher = pattern.matcher(input); if (matcher.find()) { return matcher.group(); }/*from w w w. ja v a 2 s . c o m*/ return null; }
From source file:MatcherResetExample.java
public static void test() { Pattern p = Pattern.compile("\\d"); Matcher m1 = p.matcher("01234"); while (m1.find()) { System.out.println("\t\t" + m1.group()); }/*from w w w .j a v a 2 s .c o m*/ m1.reset(); System.out.println("After resetting the Matcher"); while (m1.find()) { System.out.println("\t\t" + m1.group()); } }
From source file:MatcherResetCharSequenceExample.java
public static void test() { String output = ""; Pattern p = Pattern.compile("\\d"); Matcher m1 = p.matcher("01234"); while (m1.find()) { System.out.println("\t\t" + m1.group()); }/* w w w .j a va2 s . co m*/ //now reset the matcher with new data m1.reset("56789"); System.out.println("After resetting the Matcher"); //iterate through the matcher while (m1.find()) { System.out.println("\t\t" + m1.group()); } }
From source file:Main.java
public static String findAppId(String storeLink) { Matcher matcher = PATTERN_ID.matcher(storeLink); return matcher.find() ? matcher.group() : ""; }
From source file:Main.java
public static List<String> collect(String str) { List<String> list = new ArrayList<String>(); Pattern p = Pattern.compile("\\[.+?\\]+"); Matcher m = p.matcher(str); while (m.find()) list.add(m.group()); return list;// w ww . j ava 2s . co m }
From source file:Main.java
public static String getFileName(String path) { Pattern pattern = Pattern.compile("[^\\" + File.separator + "]+.xml"); Matcher matcher = pattern.matcher(path); if (matcher.find()) return matcher.group().substring(0, matcher.group().length() - 4); return ""; }
From source file:Main.java
public static String getVerifyCodeFromSms(String smsBody) { Pattern pattern = Pattern.compile("\\d{6}"); Matcher matcher = pattern.matcher(smsBody); if (matcher.find()) { return matcher.group(); }/*from w w w .j a va 2 s. com*/ return null; }
From source file:Main.java
/** * Search for patterns [key=value] and returns the value given the key. * /* w ww . java2 s . co m*/ * @param key * @param string * @return */ public static String lookupParameterValue(String key, String string) { Pattern p = Pattern.compile("\\[" + key + "=[^\\]]*\\]"); Matcher m = p.matcher(string); m.find(); String f = m.group(); int p1 = f.indexOf('='); int p2 = f.indexOf(']'); return f.substring(p1 + 1, p2); }