本文整理汇总了Java中java.util.regex.MatchResult.end方法的典型用法代码示例。如果您正苦于以下问题:Java MatchResult.end方法的具体用法?Java MatchResult.end怎么用?Java MatchResult.end使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.regex.MatchResult
的用法示例。
在下文中一共展示了MatchResult.end方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: skipQuoted
import java.util.regex.MatchResult; //导入方法依赖的package包/类
int skipQuoted(String line, Matcher quote, MatchResult q) {
// First is a quote, skip until next (not escaped) quote is seen
int p = q.end();
int p1 = quoteRestart(q);
MatchResult q1 = find(quote, p1);
if (q1 == null) {
// No more quotes in the line, we are inside a string not closed in this line
eventHandler.onQuoted(line.substring(p), true, false);
isInsideString = true;
p = line.length();
} else {
// Emit this string and advance
eventHandler.onQuoted(line.substring(p, quoteStart(q1)), true, true);
p = q1.end();
}
return p;
}
示例2: skipBlockComment
import java.util.regex.MatchResult; //导入方法依赖的package包/类
int skipBlockComment(String line, Matcher blockCommentEnd, MatchResult bcs) {
// We go through a block comment start and look for a block comment end
int p = bcs.end();
MatchResult bce = find(blockCommentEnd, p);
if (bce == null) {
// No block comment end found in this line, start a multi-line comment
eventHandler.onBlockComment(line.substring(p), true, false);
isInsideBlockComment = true;
p = line.length();
} else {
// Emit this block comment and advance
eventHandler.onBlockComment(line.substring(p, bce.start()), true, true);
p = bce.end();
}
return p;
}
示例3: checkPosConstraint
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* Check whether the part of speech constraint defined in a rule is satisfied.
* @param s
* @param posConstraint
* @param m
* @param jcas
* @return
*/
public boolean checkPosConstraint(Sentence s, String posConstraint, MatchResult m, JCas jcas) {
Pattern paConstraint = Pattern.compile("group\\(([0-9]+)\\):(.*?):");
for (MatchResult mr : Toolbox.findMatches(paConstraint,posConstraint)) {
int groupNumber = Integer.parseInt(mr.group(1));
int tokenBegin = s.getBegin() + m.start(groupNumber);
int tokenEnd = s.getBegin() + m.end(groupNumber);
String pos = mr.group(2);
String pos_as_is = getPosFromMatchResult(tokenBegin, tokenEnd ,s, jcas);
if (pos_as_is.matches(pos)) {
Logger.printDetail("POS CONSTRAINT IS VALID: pos should be "+pos+" and is "+pos_as_is);
} else {
return false;
}
}
return true;
}
示例4: replaceMatches
import java.util.regex.MatchResult; //导入方法依赖的package包/类
public String replaceMatches(CharSequence charSequence, Callback callback) throws CallbackMatcherException {
StringBuilder result = new StringBuilder(charSequence);
final Matcher matcher = this.pattern.matcher(charSequence);
int offset = 0;
while (matcher.find()) {
final MatchResult matchResult = matcher.toMatchResult();
final String replacement = callback.foundMatch(matchResult);
if (replacement == null) {
continue;
}
int matchStart = offset + matchResult.start();
int matchEnd = offset + matchResult.end();
result.replace(matchStart, matchEnd, replacement);
int matchLength = matchResult.end() - matchResult.start();
int lengthChange = replacement.length() - matchLength;
offset += lengthChange;
}
return result.toString();
}
示例5: doValidationAgainstRegex
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* Validates a string by regex expression
*
* @param input
* the input of a form field.
* @param regex
* a regular expression for the given string, can be {@code null}
* @param fieldName
* Name of the field the check is against.
* @param errors
* The errors to put the error into.
* @return The message key for the error.
*/
private static String doValidationAgainstRegex(String input, String regex, String fieldName,
Errors errors) {
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(input == null ? "" : input);
if (!matcher.matches()) {
errors.rejectValue(fieldName, getRegexErrorMessageKey(regex),
new Object[] { getRegexForDisplay(regex) }, "");
return getRegexErrorMessageKey(regex);
}
MatchResult res = matcher.toMatchResult();
if (res.start() != 0 || res.end() != input.length()) {
errors.rejectValue(fieldName, getRegexErrorMessageKey(regex),
new Object[] { getRegexForDisplay(regex) }, "");
return getRegexErrorMessageKey(regex);
}
return null;
}
示例6: substitute
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* Do a content substitution by looking at the array size and looking for {0}...{n} strings and replace them with
* the array's content.<br>
* (Note - we use this method and not the NLS.bind() because it does not handle well code blocks existence)
*
* @param content
* @param substitutions
* @return A string, substituted with the array's content.
*/
private static String substitute(String content, String[] substitutions)
{
StringBuilder buffer = new StringBuilder(content);
Matcher matcher = SUBSTITUTION_PATTERN.matcher(content);
int offset = 0;
while (matcher.find())
{
MatchResult matchResult = matcher.toMatchResult();
int beginIndex = matchResult.start();
int endIndex = matchResult.end();
int index = Integer.parseInt(content.substring(beginIndex + 1, endIndex - 1));
if (index >= 0 && index < substitutions.length)
{
String replacement = substitutions[index];
int matchLength = endIndex - beginIndex;
buffer.replace(offset + beginIndex, offset + endIndex, replacement);
offset += (replacement.length() - matchLength);
}
}
return buffer.toString();
}
示例7: getStringFromRegEx
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
*
* @param str
* @param regex
* @return null if substring not found.
*/
public static String getStringFromRegEx(String str, String regex) {
Pattern pa = Pattern.compile(regex);
Matcher ma = pa.matcher(str);
int start = -1;
int end = -1;
if(ma.find()){
MatchResult mr = ma.toMatchResult();
start = mr.start();
end = mr.end();
} else {
return null;
}
return str.substring(start,end);
}
示例8: getAttributStartEnd
import java.util.regex.MatchResult; //导入方法依赖的package包/类
private Location[] getAttributStartEnd(String attributRegion, Location locStart, Node attr) {
Location[] startEnd = new Location[2];
Matcher matcher = attrPattern.matcher(attributRegion);
// debug-error! can not be debugged...
while (matcher.find()) {
String name = matcher.group(1);
if (name.equals(attr.getNodeName())) {
MatchResult mresult = matcher.toMatchResult();
int startPos = mresult.start();
int endPos = mresult.end();
startEnd[0] = NodeInfo.newLocation(locStart, startPos);
startEnd[1] = NodeInfo.newLocation(locStart, endPos);
break;
}
}
return startEnd;
}
示例9: replaceAll
import java.util.regex.MatchResult; //导入方法依赖的package包/类
private static String replaceAll(Pattern pattern, CharSequence charSequence, Callback callback) {
Matcher matcher = pattern.matcher(charSequence);
StringBuilder sb = new StringBuilder(charSequence);
int offset = 0;
while (matcher.find()) {
MatchResult matchResult = matcher.toMatchResult();
String replacement = callback.foundMatch(matchResult);
int matchStart = offset + matchResult.start();
int matchEnd = offset + matchResult.end();
sb.replace(matchStart, matchEnd, replacement);
int matchLength = matchResult.end() - matchResult.start();
int lengthChange = replacement.length() - matchLength;
offset += lengthChange;
}
return sb.toString();
}
示例10: veto
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* Checks whether a possible match is being vetoed by a non split match. A
* possible match is vetoed if it any nay overlap with a veto region.
*
* @param split
* the match result representing the split to be tested
* @param vetoRegions
* regions where matches are not allowed. For efficiency reasons,
* this method assumes these regions to be non overlapping and
* sorted in ascending order. All veto regions that end before
* the proposed match are also discarded (again for efficiency
* reasons). This requires the proposed matches to be sent to
* this method in ascending order, so as to avoid malfunctions.
* @return <tt>true</tt> iff the proposed split should be ignored
*/
private boolean veto(MatchResult split, List<int[]> vetoRegions) {
// if no more non splits available, accept everything
for (Iterator<int[]> vetoRegIter = vetoRegions.iterator(); vetoRegIter.hasNext();) {
int[] aVetoRegion = vetoRegIter.next();
if (aVetoRegion[1] - 1 < split.start()) {
// current veto region ends before the proposed split starts
// --> discard the veto region
vetoRegIter.remove();
} else if (split.end() - 1 < aVetoRegion[0]) {
// veto region starts after the split ends
// -> we can return false
return false;
} else {
// we have overlap
return true;
}
}
// if we got this far, all veto regions are before the split
return false;
}
示例11: modifyBuffer
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* @see com.github.rwitzel.streamflyer.experimental.stateful.util.RegexTransitionState#modifyBuffer(java.lang.StringBuilder,
* int, java.util.regex.MatchResult)
*/
@Override
protected int modifyBuffer(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
MatchResult matchResult) {
int shiftMatchResult = 0;
// delete characters before token
if (deleteCharactersBeforeToken) {
characterBuffer.delete(firstModifiableCharacterInBuffer, matchResult.start());
shiftMatchResult += matchResult.start() - firstModifiableCharacterInBuffer;
}
// delete token
if (deleteToken) {
characterBuffer.delete(matchResult.start() - shiftMatchResult, matchResult.end() - shiftMatchResult);
shiftMatchResult += matchResult.end() - matchResult.start();
}
return matchResult.end() - shiftMatchResult;
}
示例12: createResult
import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
* @param matchResult
* the {@link MatchResult} given to the {@link MatchProcessor}.
* @param newMatchEnd
* the position of the end of the matched string after the character buffer is modified.
* @param continueMatching
* See {@link MatchProcessorResult#isContinueMatching()}
* @return Returns a {@link MatchProcessorResult} that cannot cause an endless loop.
*/
protected MatchProcessorResult createResult(MatchResult matchResult, int newMatchEnd, boolean continueMatching) {
int matchStart = matchResult.start();
int matchEnd = matchResult.end();
// if the empty string is matched, then we increase the position
// to avoid endless loops
// (compare to Matcher.find() where we see the following code:
// int i = last; if(i == first) i++;
// in words: set the *from* for the next match at the
// end of the last match. if this is equal to the start
// of the last match (a match on the empty string(, then
// increase the *from* to avoid endless loops)
int offset = matchStart == matchEnd ? 1 : 0;
return new MatchProcessorResult(newMatchEnd + offset, continueMatching);
}
示例13: createNamedEntity
import java.util.regex.MatchResult; //导入方法依赖的package包/类
@Override
protected RegexNerProcessor.NamedEntity createNamedEntity(String pattern_name, MatchResult matchResult) {
return new RegexNerProcessor.NamedEntity(
matchResult.start(),
matchResult.end(),
URL_TAG
);
}
示例14: skipStart
import java.util.regex.MatchResult; //导入方法依赖的package包/类
int skipStart(String line, Matcher quote, Matcher blockCommentEnd) {
MatchResult m = null;
if (isInsideString) {
m = find(quote, 0);
} else if (isInsideBlockComment) {
m = find(blockCommentEnd, 0);
}
int p = 0;
if (m != null) {
// If we were inside block comment emit a block comment, remove the flag
if (isInsideBlockComment) {
if (m.start() > 0) {
eventHandler.onBlockComment(line.substring(0, m.start()), false, true);
}
isInsideBlockComment = false;
} else if (isInsideString) {
// If we were inside string emit a quoted string, remove the flag
if (m.start() > 0) {
eventHandler.onQuoted(line.substring(0, quoteStart(m)), false, true);
}
isInsideString = false;
}
p = m.end();
}
return p;
}
示例15: quoteRestart
import java.util.regex.MatchResult; //导入方法依赖的package包/类
int quoteRestart(MatchResult q) {
// If we want to restart the search for quotes from current result we must start search from end - 1
// because the regular expression for searching quotes looks for sequence non-quote + quote
// This fix allows to match empty quoted strings
// Only when end > 1, re-starting from 1 is wrong
return q.end() > 1 ? q.end() - 1 : q.end();
}