List of usage examples for java.util.regex Matcher pattern
public Pattern pattern()
From source file:MainClass.java
public static void main(String args[]) { Pattern p = Pattern.compile("\\d"); Matcher m1 = p.matcher("55"); Matcher m2 = p.matcher("fdshfdgdfh"); System.out.println(m1.pattern() == m2.pattern()); }
From source file:Main.java
public static void main(String args[]) { Pattern p = Pattern.compile("\\d"); Matcher m1 = p.matcher("55"); Matcher m2 = p.matcher("fdshfdgdfh"); System.out.println(m1.pattern() == m2.pattern()); // return true }
From source file:MatcherPatternExample.java
public static void test() { Pattern p = Pattern.compile("\\d"); Matcher m1 = p.matcher("55"); Matcher m2 = p.matcher("fdshfdgdfh"); System.out.println(m1.pattern() == m2.pattern()); }
From source file:bin.spider.frame.uri.TextUtils.java
/** * Utility method using a precompiled pattern instead of using the split * method of the String class.//from w w w .j a v a 2 s .c o m * * @see java.util.regex.Pattern * @param pattern precompiled Pattern to split by * @param input the character sequence to split * @return array of Strings split by pattern */ public static String[] split(String pattern, CharSequence input) { Matcher m = getMatcher(pattern, input); String[] retVal = m.pattern().split(input); recycleMatcher(m); return retVal; }
From source file:bin.spider.frame.uri.TextUtils.java
public static void recycleMatcher(Matcher m) { final Map<String, Matcher> matchers = TL_MATCHER_MAP.get(); matchers.put(m.pattern().pattern(), m); }
From source file:de.rrze.idmone.utils.jidgen.template.Parser.java
/** * Processes the given template string by splitting it into its * parts and parse each part to compile a list of according * element objects.<br/>/*from w w w .j a va2 s . c om*/ * Those are used by the template class to finally build the * result string. * * @param template * the template string to process * @return a list of elements representing the element parts inside * the template string */ public static ArrayList<IElement> getElements(String template) { // reset the hasCounter flag hasCounterElement = false; // init elements array ArrayList<IElement> elements = new ArrayList<IElement>(); // split into parts (which later become elements) ArrayList<String> parts = new ArrayList<String>(Arrays.asList(template.split(ELEMENT_DELIMITER))); //logger.debug(parts.toString()); boolean isResolver; // process the parts - here starts the fun ;) for (Iterator<String> iter = parts.iterator(); iter.hasNext();) { String currentPart = iter.next(); /* * ALTERNATIVE / RESOLVER */ Matcher m = getMatcher("^\\[(.*)\\]$", currentPart); if (m.matches()) { logger.debug( Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => ALTERNATIVE/RESOLVER"); isResolver = true; currentPart = m.group(1); } else { isResolver = false; } // parse and get the element instance IElement element = Parser.parse(currentPart); // set the resolver status element.setResolver(isResolver); // add the element elements.add(element); } return elements; }
From source file:de.rrze.idmone.utils.jidgen.template.Parser.java
/** * Helper class for the getElements() method that * matches the given element part string against * all known element patterns to determine which * element implementation to use./*from w w w.jav a 2s. c o m*/ * * @param part * the element part string to match against * @return a matching element object, representing the * given element part string */ private static IElement parse(String part) { logger.debug(Messages.getString("Parser.PROCESSING_PART") + part); Matcher m; /* * BASIC */ // Basic (e.g. a) m = getMatcher("^([a-zA-Z])$", part); if (m.matches()) { logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => BASIC"); return new BasicElement(m.group(1), m.group(1)); } /* * STATIC */ // Static (e.g. =my_prefix) m = getMatcher("^(=([a-zA-Z_0-9]*))$", part); if (m.matches()) { logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => STATIC"); return new StaticElement(m.group(1), m.group(2)); } /* * RANDOM */ // Random - exactly one (e.g. a+) or as many as specified by repetation (e.g. aaa+) m = getMatcher("^(([a-zA-Z])(\\2*)\\+)$", part); if (m.matches()) { int length = m.group(3).length() + 1; logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => RANDOM (length=" + length + ")"); return new RandomElement(m.group(1), m.group(2), length); } // Random - as many as specified by number (e.g. a3+) - zero or leading zeros are forbidden! m = getMatcher("^(([a-zA-Z])([1-9][0-9]*)\\+)$", part); if (m.matches()) { int length = Integer.parseInt(m.group(3)); logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => RANDOM (length=" + length + ")"); return new RandomElement(m.group(1), m.group(2), length); } /* * SUBSTRING */ // Substring (e.g. 1a) m = getMatcher("^(([1-9])([a-zA-Z]))$", part); if (m.matches()) { logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => SUBSTRING (first x characters)"); return new SubstringElement(m.group(1), m.group(3), 1, Integer.parseInt(m.group(2))); } // Substring (e.g. a1) m = getMatcher("^(([a-zA-Z])([1-9]))$", part); if (m.matches()) { logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => SUBSTRING (last x characters)"); return new SubstringElement(m.group(1), m.group(2), -1, // this is special and indicates that // the last x (stored in the end parameter) characters // are to be used Integer.parseInt(m.group(3))); } // Substring (e.g. 1a5) m = getMatcher("^(([1-9])([a-zA-Z])([1-9]))$", part); if (m.matches()) { logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => SUBSTRING (start, end)"); return new SubstringElement(m.group(1), m.group(3), Integer.parseInt(m.group(2)), Integer.parseInt(m.group(4))); } // Substring with start and end (e.g. a1,5) m = getMatcher("^(([a-zA-Z])([1-9]),([1-9]))$", part); if (m.matches()) { logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => SUBSTRING (start, end)"); int end = Integer.parseInt(m.group(4)); return new SubstringElement(m.group(1), m.group(2), Integer.parseInt(m.group(3)), (end <= 0) ? -1 : end // this is just to be as kind as possible to the user // -> even negative end values are interpreted ); } // Substring (e.g. a1,) m = getMatcher("^(([a-zA-Z])([1-9]),)$", part); if (m.matches()) { logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => SUBSTRING (start at x until end of the string)"); return new SubstringElement(m.group(1), m.group(2), Integer.parseInt(m.group(3)), -1); } // Substring (e.g. a,1) m = getMatcher("^(([a-zA-Z]),([1-9]))$", part); if (m.matches()) { logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => SUBSTRING (first x characters)"); return new SubstringElement(m.group(1), m.group(2), 1, Integer.parseInt(m.group(3))); } /* * COUNTER */ // Counter - exactly one (e.g. a++) or as many as specified by repetation (e.g. aaa++) m = getMatcher("^(([a-zA-Z])(\\2*)\\+\\+)$", part); if (m.matches()) { // limit number of counter elements to one if (Parser.hasCounterElement == true) { logger.fatal(Messages.getString("Parser.ONLY_ONE_COUNTER_ELEMENT_ALLOWED")); System.exit(171); } Parser.hasCounterElement = true; int length = m.group(3).length() + 1; logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => COUNTER (length=" + length + ")"); return new CounterElement(m.group(1), m.group(2), length); } // Counter - as many as specified by number (e.g. a3++) - zero or leading zeros are forbidden! m = getMatcher("^(([a-zA-Z])([1-9][0-9]*)\\+\\+)$", part); if (m.matches()) { int length = Integer.parseInt(m.group(3)); logger.debug(Messages.getString("Parser.MATCHED_PATTERN") + m.pattern() + " => COUNTER (length=" + length + ")"); return new CounterElement(m.group(1), m.group(2), length); } /* * IF WE ARE HERE, NONE OF THE ABOVE PATTERNS HAS MATCHED! */ logger.fatal(Messages.getString("Parser.NO_MATCHING_ELEMENT_FOUND") + part); System.exit(170); return null; }
From source file:com.hdfs.concat.crush.CrushReducer.java
List<String> getInputRegexList() { ArrayList<String> list = new ArrayList<String>(inputRegexList.size()); for (Matcher matcher : inputRegexList) { list.add(matcher.pattern().pattern()); }//from w w w. ja va2 s . c o m return list; }
From source file:com.cloudbees.diff.ContextualPatch.java
private void parseNormalRange(Hunk hunk, Matcher m) { if (m.pattern() == normalAddRangePattern) { hunk.baseStart = Integer.parseInt(m.group(1)); hunk.baseCount = 0;// ww w . j a va2 s . c o m hunk.modifiedStart = Integer.parseInt(m.group(2)); hunk.modifiedCount = Integer.parseInt(m.group(3)) - hunk.modifiedStart + 1; } else if (m.pattern() == normalDeleteRangePattern) { hunk.baseStart = Integer.parseInt(m.group(1)); hunk.baseCount = Integer.parseInt(m.group(2)) - hunk.baseStart + 1; hunk.modifiedStart = Integer.parseInt(m.group(3)); hunk.modifiedCount = 0; } else { hunk.baseStart = Integer.parseInt(m.group(1)); hunk.baseCount = Integer.parseInt(m.group(2)) - hunk.baseStart + 1; hunk.modifiedStart = Integer.parseInt(m.group(3)); hunk.modifiedCount = Integer.parseInt(m.group(4)) - hunk.modifiedStart + 1; } }
From source file:org.archive.util.TextUtils.java
public static void recycleMatcher(Matcher m) { // while cached, eliminate reference to potentially-large prior 'input' m.reset("");/*from w ww . ja va 2s . c om*/ final Map<String, Matcher> matchers = TL_MATCHER_MAP.get(); matchers.put(m.pattern().pattern(), m); }