当前位置: 首页>>代码示例>>Java>>正文


Java MatchResult.start方法代码示例

本文整理汇总了Java中java.util.regex.MatchResult.start方法的典型用法代码示例。如果您正苦于以下问题:Java MatchResult.start方法的具体用法?Java MatchResult.start怎么用?Java MatchResult.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.regex.MatchResult的用法示例。


在下文中一共展示了MatchResult.start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCreator

import java.util.regex.MatchResult; //导入方法依赖的package包/类
public static TokenCreator getCreator() {
    return new TokenCreator() {

        @Override
        public Pattern getPattern() {
            return EXP;
        }

        @Override
        public Token create(MatchResult matchResult, String source, int line) {
            return new Token.Variable(matchResult.group(),
                    matchResult.group(1), "|def" + matchResult.group(2),
                    source, line, matchResult.start());
        }
    };
}
 
开发者ID:h34tnet,项目名称:temporize,代码行数:17,代码来源:TokenCreator.java

示例2: 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;
}
 
开发者ID:tudarmstadt-lt,项目名称:newsleak-frontend,代码行数:25,代码来源:HeidelTimeOpenNLP.java

示例3: 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();
}
 
开发者ID:labsai,项目名称:EDDI,代码行数:26,代码来源:CallbackMatcher.java

示例4: 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;
}
 
开发者ID:Communote,项目名称:communote-server,代码行数:31,代码来源:ValidationHelper.java

示例5: 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);
}
 
开发者ID:Actelion,项目名称:openchemlib,代码行数:26,代码来源:StringFunctions.java

示例6: 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;
	}
 
开发者ID:nkutsche,项目名称:opendocs,代码行数:19,代码来源:AttributeInfo.java

示例7: 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();
}
 
开发者ID:KRMAssociatesInc,项目名称:eHMP,代码行数:22,代码来源:VistaStringUtils.java

示例8: 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;
}
 
开发者ID:ag-csw,项目名称:ExpertFinder,代码行数:36,代码来源:GATERegexSentenceSplitter.java

示例9: process

import java.util.regex.MatchResult; //导入方法依赖的package包/类
@Override
public MatchProcessorResult process(StringBuilder characterBuffer, int firstModifiableCharacterInBuffer,
        MatchResult matchResult) {

    // are there characters that belong to a noMatch?
    if (processNoMatch && noMatch.getStartPosition() < matchResult.start()) {
        // -> process the noMatch
        matchResult = noMatch.processNoMatch(characterBuffer, firstModifiableCharacterInBuffer, matchResult);
    }

    MatchProcessorResult result = delegate.process(characterBuffer, firstModifiableCharacterInBuffer, matchResult);

    // set the start position of the next noMatch
    noMatch.setStartPosition(result.getFirstModifiableCharacterInBuffer());

    return result;
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:18,代码来源:NoMatchAwareMatchProcessor.java

示例10: 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;
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:25,代码来源:RangeFilterState.java

示例11: processNoMatch

import java.util.regex.MatchResult; //导入方法依赖的package包/类
@Override
public MatchResult processNoMatch(int startPosition, StringBuilder characterBuffer,
        int firstModifiableCharacterInBuffer, MatchResult matchResult) {

    if (!betweenStartAndEnd) {
        // -> delete the noMatch

        // The end of the noMatch is given by {@link MatchResult#start()}.
        int shiftMatchResult = matchResult.start() - startPosition;
        MatchResultShifted newMatchResult = new MatchResultShifted(matchResult, characterBuffer, -shiftMatchResult);

        // delete characters before token
        characterBuffer.delete(startPosition, matchResult.start());

        return newMatchResult;

    } else {
        return null;
    }
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:21,代码来源:RangeFilterHandler.java

示例12: 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();
}
 
开发者ID:apicloudcom,项目名称:APICloud-Studio,代码行数:31,代码来源:FormatterPreviewUtils.java

示例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
    );
}
 
开发者ID:redlink-gmbh,项目名称:smarti,代码行数:9,代码来源:UrlFactory.java

示例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;
}
 
开发者ID:itesla,项目名称:ipst,代码行数:28,代码来源:CommentScanner.java

示例15: checkInfrontBehind

import java.util.regex.MatchResult; //导入方法依赖的package包/类
/**
 * Check token boundaries of expressions.
 * @param r MatchResult 
 * @param s Respective sentence
 * @return whether or not the MatchResult is a clean one
 */
public static Boolean checkInfrontBehind(MatchResult r, Sentence s) {
	Boolean ok = true;
	
	// get rid of expressions such as "1999" in 53453.1999
	if (r.start() > 1) {
		if ((s.getCoveredText().substring(r.start() - 2, r.start()).matches("\\d\\."))){
			ok = false;
		}
	}
	
	// get rid of expressions if there is a character or symbol ($+) directly in front of the expression
	if (r.start() > 0) {
		if (((s.getCoveredText().substring(r.start() - 1, r.start()).matches("[\\w\\$\\+]"))) &&
				(!(s.getCoveredText().substring(r.start() - 1, r.start()).matches("\\(")))){
			ok = false;
		}
	}
	
	if (r.end() < s.getCoveredText().length()) {
		if ((s.getCoveredText().substring(r.end(), r.end() + 1).matches("[°\\w]")) &&
				(!(s.getCoveredText().substring(r.end(), r.end() + 1).matches("\\)")))){
			ok = false;
		}
		if (r.end() + 1 < s.getCoveredText().length()) {
			if (s.getCoveredText().substring(r.end(), r.end() + 2).matches(
					"[\\.,]\\d")) {
				ok = false;
			}
		}
	}
	return ok;
}
 
开发者ID:tudarmstadt-lt,项目名称:newsleak-frontend,代码行数:39,代码来源:HeidelTimeOpenNLP.java


注:本文中的java.util.regex.MatchResult.start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。