下面列出了java.util.regex.Matcher#regionEnd ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
RuleParser(String rule) {
Matcher m = tokenizer.matcher(rule);
List<String> list = new ArrayList<>();
int end = 0;
while (m.lookingAt()) {
list.add(m.group(1));
end = m.end();
m.region(m.end(), m.regionEnd());
}
if (end != m.regionEnd()) {
throw new RuleParseError("Unexpected tokens :" + rule.substring(m.end(), m.regionEnd()));
}
tokens = list.toArray(new String[0]);
matchDescriptor = parseExpression();
if (!done()) {
throw new RuleParseError("didn't consume all tokens");
}
capturedNames.add(0, "root");
capturedTypes.add(0, matchDescriptor.nodeType);
}
private void init(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());
}
/**
* 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
*/
private void init(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());
}
/**
* 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
*/
private void init(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());
}
public static void main(String[]args) {
String text = "爱的f 123130.33CNY";//16
// Pattern pattern = Pattern.compile("\\d[A-Za-z]");//一个数字一个字母
Pattern pattern = Pattern.compile("\\d");
Matcher matcher = pattern.matcher(text);
matcher.regionEnd();//16
while (matcher.find()) {
System.out.println(""+matcher.end());
}
// System.out.println(""+matcher.end());
// matcher.regionEnd();
}
/**
* Initialize derived fields from defining fields.
* This is called from constructor and from readObject (de-serialization)
*/
private void init() {
thisYear= Calendar.getInstance(timeZone, locale).get(Calendar.YEAR);
nameValues= new ConcurrentHashMap<Integer, KeyValue[]>();
StringBuilder regex= new StringBuilder();
List<Strategy> collector = new ArrayList<Strategy>();
Matcher patternMatcher= formatPattern.matcher(pattern);
if(!patternMatcher.lookingAt()) {
throw new IllegalArgumentException("Invalid pattern");
}
currentFormatField= patternMatcher.group();
Strategy currentStrategy= getStrategy(currentFormatField);
for(;;) {
patternMatcher.region(patternMatcher.end(), patternMatcher.regionEnd());
if(!patternMatcher.lookingAt()) {
nextStrategy = null;
break;
}
String nextFormatField= patternMatcher.group();
nextStrategy = getStrategy(nextFormatField);
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());
}
/**
* Initialize derived fields from defining fields.
* This is called from constructor and from readObject (de-serialization)
*/
private void init() {
Calendar definingCalendar = Calendar.getInstance(timeZone, locale);
thisYear= definingCalendar.get(Calendar.YEAR);
StringBuilder regex= new StringBuilder();
List<Strategy> collector = new ArrayList<Strategy>();
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;
}
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());
}
/**
* Initialize derived fields from defining fields.
* This is called from constructor and from readObject (de-serialization)
*/
private void init() {
final Calendar definingCalendar = Calendar.getInstance(timeZone, locale);
thisYear= definingCalendar.get(Calendar.YEAR);
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());
}
/**
* Initialize derived fields from defining fields.
* This is called from constructor and from readObject (de-serialization)
*/
private void init() {
Calendar definingCalendar = Calendar.getInstance(timeZone, locale);
thisYear= definingCalendar.get(Calendar.YEAR);
StringBuilder regex= new StringBuilder();
List<Strategy> collector = new ArrayList<Strategy>();
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;
}
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());
}
private void init(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());
}
/**
* 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
*/
private void init(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());
}
protected List<Acronym> extractHeadNounPattern_3Parts(String text) {
ArrayList<Acronym> extractedPairs = new ArrayList<Acronym>();
String nounExp = "([a-zA-Z0-9\\-]{1,20})";
String shortFormExp = "\\(([^\\(]*?)\\)";
Matcher matcher = Pattern.compile(
nounExp + " " + nounExp + " " + shortFormExp + ",? " + nounExp
+ " " + shortFormExp + ",? and " + nounExp + " "
+ shortFormExp).matcher(text);
int startPos = 0;
while (startPos < text.length() && matcher.find(startPos)) {
String mainNoun = matcher.group(1);
String part1 = matcher.group(2);
String part1_short = matcher.group(3);
String part2 = matcher.group(4);
String part2_short = matcher.group(5);
String part3 = matcher.group(6);
String part3_short = matcher.group(7);
startPos = matcher.regionEnd() + 1;
addCandidatePair(extractedPairs, mainNoun + " " + part1,
part1_short, startPos);
addCandidatePair(extractedPairs, mainNoun + " " + part2,
part2_short, startPos);
addCandidatePair(extractedPairs, mainNoun + " " + part3,
part3_short, startPos);
}
return extractedPairs;
}
protected List<Acronym> extractHeadNounPattern_2Parts(String text) {
ArrayList<Acronym> extractedPairs = new ArrayList<Acronym>();
String nounExp = "([a-zA-Z0-9\\-]{1,20})";
String shortFormExp = "\\(([^\\(]*?)\\)";
Matcher matcher = Pattern.compile(
nounExp + " " + nounExp + " " + shortFormExp + ",? and "
+ nounExp + " " + shortFormExp).matcher(text);
int startPos = 0;
while (startPos < text.length() && matcher.find(startPos)) {
String mainNoun = matcher.group(1);
String part1 = matcher.group(2);
String part1_short = matcher.group(3);
String part2 = matcher.group(4);
String part2_short = matcher.group(5);
startPos = matcher.regionEnd() + 1;
addCandidatePair(extractedPairs, mainNoun + " " + part1,
part1_short, startPos);
addCandidatePair(extractedPairs, mainNoun + " " + part2,
part2_short, startPos);
}
return extractedPairs;
}
protected List<Acronym> extractTrailingNounPattern_3Parts(String text) {
ArrayList<Acronym> extractedPairs = new ArrayList<Acronym>();
String finalNounExp = "([a-zA-Z0-9\\-]{1,20})";
String nounExp = "(.{1,20}?)";
String shortFormExp = "\\(([^\\(]*?)\\)";
Matcher matcher = Pattern.compile(
nounExp + " " + shortFormExp + ",? " + nounExp + " "
+ shortFormExp + ",? and " + nounExp + " "
+ shortFormExp + " " + finalNounExp).matcher(text);
int startPos = 0;
while (startPos < text.length() && matcher.find(startPos)) {
String part1 = matcher.group(1);
String part1_short = matcher.group(2);
String part2 = matcher.group(3);
String part2_short = matcher.group(4);
String part3 = matcher.group(5);
String part3_short = matcher.group(6);
String mainNoun = matcher.group(7);
startPos = matcher.regionEnd() + 1;
addCandidatePair(extractedPairs, part1 + " " + mainNoun,
part1_short, startPos);
addCandidatePair(extractedPairs, part2 + " " + mainNoun,
part2_short, startPos);
addCandidatePair(extractedPairs, part3 + " " + mainNoun,
part3_short, startPos);
}
return extractedPairs;
}
protected List<Acronym> extractTrailingNounPattern_2Parts(String text) {
ArrayList<Acronym> extractedPairs = new ArrayList<Acronym>();
String finalNounExp = "([a-zA-Z0-9\\-]{1,20})";
String nounExp = "(.{1,20}?)";
String shortFormExp = "\\(([^\\(]*?)\\)";
Matcher matcher = Pattern.compile(
nounExp + " " + shortFormExp + ",? and " + nounExp + " "
+ shortFormExp + " " + finalNounExp).matcher(text);
int startPos = 0;
while (startPos < text.length() && matcher.find(startPos)) {
String part1 = matcher.group(1);
String part1_short = matcher.group(2);
String part2 = matcher.group(3);
String part2_short = matcher.group(4);
String mainNoun = matcher.group(5);
startPos = matcher.regionEnd() + 1;
addCandidatePair(extractedPairs, part1 + " " + mainNoun,
part1_short, startPos);
addCandidatePair(extractedPairs, part2 + " " + mainNoun,
part2_short, startPos);
}
return extractedPairs;
}
/**
* 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
*/
private void init(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());
}