List of usage examples for java.util.regex Matcher region
public Matcher region(int start, int end)
From source file:org.openengsb.core.ekb.transformation.wonderland.internal.performer.TransformationPerformer.java
/** * Logic for the remove leading step//w w w.j ava2 s .c om */ private void performRemoveLeadingStep(TransformationStep step) throws Exception { String value = getTypedObjectFromSourceField(step.getSourceFields()[0], String.class); String regex = step.getOperationParamater(TransformationConstants.regexParam); String lengthString = step.getOperationParamater(TransformationConstants.removeLeadingLength); Integer length = TransformationPerformUtils.parseIntString(lengthString, false, 0); Matcher matcher = TransformationPerformUtils.generateMatcher(regex, value); if (length != null && length != 0) { matcher.region(0, length); } if (matcher.find()) { String matched = matcher.group(); value = value.substring(matched.length()); } setObjectToTargetField(step.getTargetField(), value); }
From source file:org.sqlite.date.FastDateParser.java
/** * Initialize derived fields from defining fields. * This is called from constructor and from readObject (de-serialization) * * @param definingCalendar the {@link java.util.Calendar} instance used to initialize this FastDateParser *//*ww w . j a v a 2 s. com*/ private void init(final Calendar definingCalendar) { final StringBuilder regex = new StringBuilder(); final List<Strategy> collector = new ArrayList<Strategy>(); final Matcher patternMatcher = formatPattern.matcher(pattern); if (!patternMatcher.lookingAt()) { throw new IllegalArgumentException( "Illegal pattern character '" + pattern.charAt(patternMatcher.regionStart()) + "'"); } currentFormatField = patternMatcher.group(); Strategy currentStrategy = getStrategy(currentFormatField, definingCalendar); for (;;) { patternMatcher.region(patternMatcher.end(), patternMatcher.regionEnd()); if (!patternMatcher.lookingAt()) { nextStrategy = null; break; } final String nextFormatField = patternMatcher.group(); nextStrategy = getStrategy(nextFormatField, definingCalendar); if (currentStrategy.addRegex(this, regex)) { collector.add(currentStrategy); } currentFormatField = nextFormatField; currentStrategy = nextStrategy; } if (patternMatcher.regionStart() != patternMatcher.regionEnd()) { throw new IllegalArgumentException( "Failed to parse \"" + pattern + "\" ; gave up at index " + patternMatcher.regionStart()); } if (currentStrategy.addRegex(this, regex)) { collector.add(currentStrategy); } currentFormatField = null; strategies = collector.toArray(new Strategy[collector.size()]); parsePattern = Pattern.compile(regex.toString()); }
From source file:org.xchain.framework.util.AttributesUtil.java
/** * Parses an attribute value template into fixed and dynamic parts. This list will always start with a fixed part and * then include alternating dynamic and fixed parts. *//*from ww w . ja va2 s . co m*/ public static List<String> parseAttributeValueTemplate(String attributeValueTemplate) throws SAXException { // the result. ArrayList<String> result = new ArrayList<String>(); // create the matcher. Matcher matcher = attributeValueTemplatePattern.matcher(attributeValueTemplate); while (matcher.lookingAt()) { String fixedPart = matcher.group(1); String dynamicPart = matcher.group(2); if (result.isEmpty() && fixedPart == null) { result.add(""); } if (fixedPart != null) { result.add(fixedPart.replaceAll("\\{\\{", "{").replaceAll("\\}\\}", "}")); } if (dynamicPart != null) { result.add(dynamicPart); } matcher.region(matcher.regionStart() + matcher.group().length(), matcher.regionEnd()); } if (!matcher.hitEnd()) { throw new SAXException( "The attribute value template '" + attributeValueTemplate + "' has an error between characters " + matcher.regionStart() + " and " + matcher.regionEnd() + "."); } return result; }