本文整理匯總了Java中java.util.regex.Matcher.end方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.end方法的具體用法?Java Matcher.end怎麽用?Java Matcher.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.regex.Matcher
的用法示例。
在下文中一共展示了Matcher.end方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: parseStandardFormat
import java.util.regex.Matcher; //導入方法依賴的package包/類
private static Duration parseStandardFormat(boolean isNegative, String source)
{
Matcher matcher = STANDARD_PATTERN.matcher(source);
if (!matcher.find())
throw invalidRequest("Unable to convert '%s' to a duration", source);
Builder builder = new Builder(isNegative);
boolean done = false;
do
{
long number = groupAsLong(matcher, 1);
String symbol = matcher.group(2);
add(builder, number, symbol);
done = matcher.end() == source.length();
}
while (matcher.find());
if (!done)
throw invalidRequest("Unable to convert '%s' to a duration", source);
return builder.build();
}
示例2: tokenize
import java.util.regex.Matcher; //導入方法依賴的package包/類
public List<Tokenization> tokenize(List<String> sentences) {
List<Tokenization> tokenizations = new ArrayList<>();
int accumulatedSentenceLength = 0;
for (String sentence : sentences) {
int index = 0;
Matcher matcher = pattern.matcher(sentence);
List<Token> tokens = new ArrayList<>();
while (matcher.find()) {
String text = matcher.group();
int from = matcher.start();
int to = matcher.end();
tokens.add(new Token(index, from, to, text));
index++;
}
Tokenization tokenization = new Tokenization(tokens, sentence, accumulatedSentenceLength);
tokenizations.add(tokenization);
accumulatedSentenceLength += sentence.length();
// System.out.println(tokenization.originalSentence);
// System.out.println(
// tokenization.tokens.stream().reduce("", (s, t) -> s + " " +
// t.getText(), (s, tt) -> s + tt));
}
return tokenizations;
}
示例3: classifyGaps
import java.util.regex.Matcher; //導入方法依賴的package包/類
public List<AlignmentGap> classifyGaps() {
// insertion interfered the position calculation of codons,
// this's the offset variable so we can shift them back
int codonOffset = 0;
List<AlignmentGap> gaps = new ArrayList<AlignmentGap>();
String dashesRegex = "(\\-+)";
Pattern dashes = Pattern.compile(dashesRegex);
Matcher matchedDashes = dashes.matcher(controlLine);
while (matchedDashes.find()) {
int gapStart = matchedDashes.start();
int gapEnd = matchedDashes.end();
if (IsInsertion(gapStart)) {
gaps.addAll(findGapsBetween(
gapStart, gapEnd, AlignmentGapType.FRAME_SHIFT_INSERTION,
AlignmentGapType.INSERTION, codonOffset, true));
codonOffset -= gapEnd - gapStart;
}
else {
gaps.addAll(findGapsBetween(
gapStart, gapEnd, AlignmentGapType.FRAME_SHIFT_DELETION,
AlignmentGapType.DELETION, codonOffset, false));
}
}
return gaps;
}
示例4: setActionFromFormByIndex
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Searches content for form tag with given text and extracts the <code>action</code> attribute.<br/>
* This method is useful where the FORM tags has empty body or there is only 1 FORM tag in the content.
* <p>
* <b>Content:</b><br/>
* <code>...<br/><form action="http://blabla1/" >hahahaha<form><br />
* <form action="http://blabla2/" >hahahaha<form><br/>...<br/></code>
* <br /><b>Using:</b>
* <code><br />setActionFromFormByIndex(1)</code> - an action <code>http://blabla1/</code> will be extracted<br/>
* <i>also this is possible:</i>
* <code><br />setActionFromFormByIndex(2)</code> - an action <code>http://blabla2/</code> will be extracted<br/>
* </p>
* <p>All <code>&amp;</code> entity is replaced to <code>&</code> by default.</p>
*
* @param index index of the form tag in the content - the lowest index has number 1
* @param useFormParameters if true then it extracts all input parameters from the <code>form</code> tag
* @return builder instance
* @throws cz.vity.freerapid.plugins.exceptions.BuildMethodException
* when no such FORM with text in the tag was found
*/
public MethodBuilder setActionFromFormByIndex(final int index, final boolean useFormParameters) throws BuildMethodException {
if (index < 1)
throw new IllegalArgumentException("Index must be higher or equal to 1");
final Matcher formMatcher = getFormMatcher();
int start = 0;
int count = 1;
boolean found = false;
while (formMatcher.find(start)) {
if (count++ == index) {
found = true;
inputForm(useFormParameters, formMatcher.group(FORM_MATCHER_TITLE_GROUP), formMatcher.group(FORM_MATCHER_FORM_CONTENT));
break;
}
start = formMatcher.end();
}
if (!found) {
throw new BuildMethodException("<Form> with index " + index + " from the top was not found");
}
return this;
}
示例5: matchMention
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static Spannable matchMention(Spannable spannable) {
String text = spannable.toString();
Pattern pattern = Pattern.compile(MATCH_MENTION);
Matcher matcher = pattern.matcher(text);
while (matcher.find()) {
String str = matcher.group();
int matcherStart = matcher.start();
int matcherEnd = matcher.end();
spannable.setSpan(new RichEditText.TagSpan(str), matcherStart, matcherEnd, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
log("matchMention:" + str + " " + matcherStart + " " + matcherEnd);
}
return spannable;
}
示例6: search
import java.util.regex.Matcher; //導入方法依賴的package包/類
private Result search(int start, String pattern, String text, boolean canHandleCarriageReturn) {
if (!canHandleCarriageReturn) {
text = Tools.transformAllLineSeparators(text);
}
if (regExp.isSelected()) {
Matcher matcher = Pattern.compile(pattern, caseSensitive.isSelected() ? 0 : Pattern.CASE_INSENSITIVE)
.matcher(text.subSequence(start, text.length()));
if (matcher.find()) {
return new Result(start + matcher.start(), start + matcher.end());
} else {
return null;
}
} else {
if (!caseSensitive.isSelected()) {
text = text.toLowerCase();
pattern = pattern.toLowerCase();
}
int result = text.indexOf(pattern, start);
if (result == -1) {
return null;
} else {
return new Result(result, result + pattern.length());
}
}
}
示例7: highLight
import java.util.regex.Matcher; //導入方法依賴的package包/類
private static String highLight(String s, Pattern pattern) {
Matcher matcher = pattern.matcher(s);
int idx = 0;
StringBuilder sb = new StringBuilder();
while (matcher.find(idx)) {
int start = matcher.start();
int end = matcher.end();
if (start == end) {
break;
}
sb.append(s.substring(idx, start));
sb.append("<font bgcolor=\"FFB442\" color=\"black\">");
sb.append(s.substring(start, end));
sb.append("</font>");
idx = matcher.end();
}
if(sb.length() > 0) {
sb.append(idx < s.length() ? s.substring(idx, s.length()) : "");
s = sb.toString();
}
return s;
}
示例8: parse
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static void parse(Pattern pattern, String src, Consumer<Either<String, Matcher>> consumer) {
Matcher matcher = pattern.matcher(src);
int lastEnd=0;
while (matcher.find()) {
consumer.accept(Either.left(src.substring(lastEnd,matcher.start())));
consumer.accept(Either.right(matcher));
lastEnd=matcher.end();
}
consumer.accept(Either.left(src.substring(lastEnd)));
}
示例9: getNextByRegex
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Get the next token by a regex.
*
* @param pattern The regex pattern.
* @return A regex token, contains the matcher.
*/
public RegexToken getNextByRegex(Pattern pattern) {
if (!matchesRegex(pattern)) {
throw new IllegalArgumentException("Next \"Regex Match\" not found!");
}
Matcher matcher = pattern.matcher(remain);
final int end = cursor + matcher.end();
RegexToken token = new RegexToken(matcher.group(), cursor + matcher.start(), end, matcher);
jumpTo(cursor + end);
return token;
}
示例10: matchWhiteSpaceDelimnatedWords
import java.util.regex.Matcher; //導入方法依賴的package包/類
public void matchWhiteSpaceDelimnatedWords(CharBuffer cb, WordListener wl) {
Matcher m = SPACE_PATTERN.matcher(cb);
int i = 0;
int s = 0;
while(m.find()) {
s = m.start();
if (s != i) {
wl.word(i, s);
}
i = m.end();
}
if (i != cb.length())
wl.word(i, cb.length());
}
示例11: SimpleTextFormat
import java.util.regex.Matcher; //導入方法依賴的package包/類
public SimpleTextFormat(@Nonnull final String format, @Nonnull final Pattern variablePattern) {
this.format = format;
final Matcher matcher = variablePattern.matcher(format);
int pos = 0;
tokens = new ArrayList<>();
while (matcher.find(pos)) {
int start = matcher.start();
if (start > pos) {
tokens.add(new TextToken(format.substring(pos, start)));
}
final String name = matcher.group(1);
final Token stdAttr = STD_ATTRS.get(name);
if (stdAttr != null) {
tokens.add(stdAttr);
} else {
tokens.add(new AttributeToken(name));
}
pos = matcher.end();
}
if (pos < format.length()) {
tokens.add(new TextToken(format.substring(pos)));
}
tokens.trimToSize();
}
示例12: getHighLightKeyWord
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* @param color 關鍵字顏色
* @param text 文本
* @param keyword 關鍵字
* @return
*/
public static SpannableString getHighLightKeyWord(int color, String text, String keyword)
{
SpannableString s = new SpannableString(text);
Pattern p = Pattern.compile(keyword);
Matcher m = p.matcher(s);
while (m.find())
{
int start = m.start();
int end = m.end();
s.setSpan(new ForegroundColorSpan(color), start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return s;
}
示例13: Highlighter
import java.util.regex.Matcher; //導入方法依賴的package包/類
public Highlighter(String text) {
String stripped = STRIPPER.matcher(text).replaceAll("");
mask = new boolean[stripped.length()];
Matcher m = HIGHLIGHTER.matcher(stripped);
int pos = 0;
int lastMatch = 0;
while (m.find()) {
pos += (m.start() - lastMatch);
int groupLen = m.group(1).length();
for (int i = pos; i < pos + groupLen; i++) {
mask[i] = true;
}
pos += groupLen;
lastMatch = m.end();
}
m.reset(text);
StringBuffer sb = new StringBuffer();
while (m.find()) {
m.appendReplacement(sb, m.group(1));
}
m.appendTail(sb);
this.text = sb.toString();
}
示例14: deleteLeftWord
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Deletes all characters up to the leftmost whitespace from the cursor (including the whitespace).
* If something is selected then delete the selection.
* TODO: maybe expensive?
*/
@Override
public boolean deleteLeftWord() {
mInputConnection.beginBatchEdit();
// If something is selected then delete the selection and return
if (mInputConnection.getSelectedText(0) != null) {
mInputConnection.commitText("", 0);
} else {
CharSequence beforeCursor = mInputConnection.getTextBeforeCursor(MAX_DELETABLE_CONTEXT, 0);
if (beforeCursor != null) {
int beforeCursorLength = beforeCursor.length();
Matcher m = WHITESPACE_AND_TOKEN.matcher(beforeCursor);
int lastIndex = 0;
while (m.find()) {
// If the cursor is immediately left from WHITESPACE_AND_TOKEN, then
// delete the WHITESPACE_AND_TOKEN, otherwise delete whatever is in between.
lastIndex = beforeCursorLength == m.end() ? m.start() : m.end();
}
if (lastIndex > 0) {
mInputConnection.deleteSurroundingText(beforeCursorLength - lastIndex, 0);
} else if (beforeCursorLength < MAX_DELETABLE_CONTEXT) {
mInputConnection.deleteSurroundingText(beforeCursorLength, 0);
}
}
}
mInputConnection.endBatchEdit();
return true;
}
開發者ID:vaibhavs4424,項目名稱:AI-Powered-Intelligent-Banking-Platform,代碼行數:33,代碼來源:InputConnectionCommandEditor.java
示例15: highlight
import java.util.regex.Matcher; //導入方法依賴的package包/類
private void highlight(Component comp, boolean cancel) {
if (comp == bar) {
return;
}
if (comp instanceof JTextPane) {
JTextPane tcomp = (JTextPane)comp;
if(!tcomp.isVisible()) {
return;
}
String txt = tcomp.getText();
Matcher matcher = pattern.matcher(txt);
Highlighter highlighter = tcomp.getHighlighter();
if (cancel) {
highlighter.removeAllHighlights();
} else {
int idx = 0;
while (matcher.find(idx)) {
int start = matcher.start();
int end = matcher.end();
if (start == end) {
break;
}
try {
highlighter.addHighlight(start, end, highlighterAll);
} catch (BadLocationException blex) {
BugtrackingManager.LOG.log(Level.INFO, blex.getMessage(), blex);
}
idx = matcher.end();
}
}
} else if (comp instanceof Container) {
Container cont = (Container)comp;
for (Component subComp : cont.getComponents()) {
highlight(subComp, cancel);
}
}
}