public static Author fromString(String nameAndEmail) { Matcher matcher = EMAIL.matcher(nameAndEmail); String name, email; if(!matcher.find()) { name = nameAndEmail.trim(); email = null; } else { name = nameAndEmail.substring(0, matcher.regionStart()); email = matcher.group(1).replace(" [at] ", "@"); } return new Author(name, email); } }
/** * 显示 Matcher 的详细信息 * * @param m * Matcher 对象,必须执行过 find * @return 信息 */ public static String matcherFound(Matcher m) { StringBuilder sb = new StringBuilder(); sb.append(String.format("%d/%d Regin:%d/%d\n", m.start(), m.end(), m.regionStart(), m.regionEnd())); for (int i = 0; i <= m.groupCount(); i++) sb.append(String.format("%2d:[%3d,%3d) %s\n", i, m.start(i), m.end(i), m.group(i))); return sb.toString(); }
/** * Returns a string representing this {@code Matcher}. * The format of this string is unspecified. */ @Override public String toString() { return getClass().getName() + "[pattern=" + pattern() + " region=" + regionStart() + "," + regionEnd() + " lastmatch=" + (matchFound ? group() : "") + "]"; }
if (!patternMatcher.lookingAt()) { throw new IllegalArgumentException( "Illegal pattern character '" + pattern.charAt(patternMatcher.regionStart()) + "'"); currentStrategy = nextStrategy; if (patternMatcher.regionStart() != patternMatcher.regionEnd()) { throw new IllegalArgumentException("Failed to parse \"" + pattern + "\" ; gave up at index " + patternMatcher.regionStart());
if (!patternMatcher.lookingAt()) { throw new IllegalArgumentException( "Illegal pattern character '" + pattern.charAt(patternMatcher.regionStart()) + "'"); currentStrategy = nextStrategy; if (patternMatcher.regionStart() != patternMatcher.regionEnd()) { throw new IllegalArgumentException("Failed to parse \"" + pattern + "\" ; gave up at index " + patternMatcher.regionStart());
while (pos < matcher.regionStart()) { if (text.charAt(pos) == '\n') { ++line; if (matcher.regionStart() == matcher.regionEnd()) {
while (pos < matcher.regionStart()) { if (text.charAt(pos) == '\n') { ++line; if (matcher.regionStart() == matcher.regionEnd()) {
@FastMethod @Signature public Memory regionStart(Environment env, Memory... args) { return LongMemory.valueOf(matcher.regionStart()); }
throw error(matcher.regionStart(), "cannot parse");
while (pos < matcher.regionStart()) { if (text.charAt(pos) == '\n') { ++line; if (matcher.regionStart() == matcher.regionEnd()) {
/** * Reports the start index of this matcher's region. The searches this * matcher conducts are limited to finding matches within regionStart * (inclusive) and regionEnd (exclusive). * * @return The starting point of this matcher's region */ public int regionStart() { return matcher.regionStart(); }
public int regionStart() { return matcher.regionStart(); }
/** * Reports the start index of this matcher's region. The searches this * matcher conducts are limited to finding matches within regionStart * (inclusive) and regionEnd (exclusive). * * @return The starting point of this matcher's region */ public int regionStart() { return matcher.regionStart(); }
String inputString1 = "asdasd|adajjsd|asas,asdas|asda|sd"; String regex = "([a-z]*\\|[a-z]*\\|[a-z]*\\,?)+"; Pattern pattern1 = Pattern.compile(regex); Matcher matcher1 = pattern1.matcher(inputString1); boolean result = matcher1.find(); System.out.println(inputString1.substring(matcher1.regionStart(), matcher1.regionEnd()));
/** * Returns a string representing this {@code Matcher}. * The format of this string is unspecified. */ @Override public String toString() { return getClass().getName() + "[pattern=" + pattern() + " region=" + regionStart() + "," + regionEnd() + " lastmatch=" + (matchFound ? group() : "") + "]"; }
/** * Returns a string representing this {@code Matcher}. * The format of this string is unspecified. */ @Override public String toString() { return getClass().getName() + "[pattern=" + pattern() + " region=" + regionStart() + "," + regionEnd() + " lastmatch=" + (matchFound ? group() : "") + "]"; }
/** * Returns a string representing this {@code Matcher}. * The format of this string is unspecified. */ @Override public String toString() { return getClass().getName() + "[pattern=" + pattern() + " region=" + regionStart() + "," + regionEnd() + " lastmatch=" + (matchFound ? group() : "") + "]"; }
/** * Returns a string representing this {@code Matcher}. * The format of this string is unspecified. */ @Override public String toString() { return getClass().getName() + "[pattern=" + pattern() + " region=" + regionStart() + "," + regionEnd() + " lastmatch=" + (matchFound ? group() : "") + "]"; }
/** * Returns a string representing this {@code Matcher}. * The format of this string is unspecified. */ @Override public String toString() { return getClass().getName() + "[pattern=" + pattern() + " region=" + regionStart() + "," + regionEnd() + " lastmatch=" + (matchFound ? group() : "") + "]"; }
/** * Returns a string representing this {@code Matcher}. * The format of this string is unspecified. */ @Override public String toString() { return getClass().getName() + "[pattern=" + pattern() + " region=" + regionStart() + "," + regionEnd() + " lastmatch=" + (matchFound ? group() : "") + "]"; }