java.util.regex.Matcher.hitEnd()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.1k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中java.util.regex.Matcher.hitEnd()方法的一些代码示例,展示了Matcher.hitEnd()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matcher.hitEnd()方法的具体详情如下:
包路径:java.util.regex.Matcher
类名称:Matcher
方法名:hitEnd

Matcher.hitEnd介绍

[英]Boolean indicating whether or not more input could change the results of the last match. If hitEnd is true, and a match was found, then more input might cause a different match to be found. If hitEnd is true and a match was not found, then more input could cause a match to be found. If hitEnd is false and a match was found, then more input will not change the match. If hitEnd is false and a match was not found, then more input will not cause a match to be found.
[中]布尔值,指示多个输入是否可以更改上次匹配的结果。如果hitEnd为true,并且找到了匹配项,则更多的输入可能会导致找到不同的匹配项。如果hitEnd为true,但未找到匹配项,则更多输入可能导致找到匹配项。如果hitEnd为false且找到匹配项,则更多输入将不会更改匹配项。如果hitEnd为false且未找到匹配项,则更多输入将不会导致找到匹配项。

代码示例

代码示例来源:origin: org.codehaus.groovy/groovy

/**
 * Given a matcher that matches a string against a pattern,
 * this method returns true when the string matches the pattern or if a longer string, could match the pattern.
 *
 * For example:
 * <pre class="groovyTestCase">
 *     def emailPattern = /\w+@\w+\.\w{2,}/
 *
 *     def matcher = "john@doe" =~ emailPattern
 *     assert matcher.matchesPartially()
 *
 *     matcher = "john@doe.com" =~ emailPattern
 *     assert matcher.matchesPartially()
 *
 *     matcher = "john@@" =~ emailPattern
 *     assert !matcher.matchesPartially()
 * </pre>
 *
 * @param matcher the Matcher
 * @return true if more input to the String could make the matcher match the associated pattern, false otherwise.
 *
 * @since 2.0.0
 */
public static boolean matchesPartially(Matcher matcher) {
  return matcher.matches() || matcher.hitEnd();
}

代码示例来源:origin: cucumber/cucumber-jvm

public boolean matches(String text) {
  Pattern p = pattern();
  Matcher m = p.matcher(text);
  return m.matches() || m.hitEnd();
}

代码示例来源:origin: stackoverflow.com

import java.util.regex.*;

public class Test
{
 public static void main(String[] args) throws Exception
 {
  String[] ss = { "aabb", "aa", "cc", "aac" };
  Pattern p = Pattern.compile("aabb");
  Matcher m = p.matcher("");

  for (String s : ss) {
   m.reset(s);
   if (m.matches()) {
    System.out.printf("%-4s : match%n", s);
   }
   else if (m.hitEnd()) {
    System.out.printf("%-4s : partial match%n", s);
   }
   else {
    System.out.printf("%-4s : no match%n", s);
   }
  }
 }
}

代码示例来源:origin: spockframework/spock

public static String camelCaseToConstantCase(String value) {
 if (value == null || "".equals(value)) return value;
 StringBuilder result = new StringBuilder();
 Matcher matcher = LOWER_UPPER.matcher(value);
 while (matcher.find()) {
  String lowers = matcher.group(1);
  String uppers = matcher.group(2);
  if (uppers.length() == 0) {
   result.append(lowers.toUpperCase());
  } else {
   if (lowers.length() > 0) {
    result.append(lowers.toUpperCase());
    result.append('_');
   }
   if (uppers.length() > 1 && !matcher.hitEnd()) {
    result.append(uppers.substring(0, uppers.length() - 1));
    result.append('_');
    result.append(uppers.charAt(uppers.length() - 1));
   } else {
    result.append(uppers);
   }
  }
 }
 return result.toString();
}

代码示例来源:origin: jphp-group/jphp

@FastMethod
@Signature
public Memory hitEnd(Environment env, Memory... args) {
  return matcher.hitEnd() ? Memory.TRUE : Memory.FALSE;
}

代码示例来源:origin: robovm/robovm

if ((horizon == 0 && !matcher.hitEnd()) || isHorizonInBuffer || inputExhausted) {
  result = matcher.group();
  break;

代码示例来源:origin: stackoverflow.com

String[] inputs = { "AA", "BB" };
Pattern p = Pattern.compile("AAAAAB");
Matcher m = p.matcher("");
for (String s : inputs)
{
 m.reset(s);
 System.out.printf("%s -- full match: %B; partial match: %B%n",
          s, m.matches(), m.hitEnd());
}

代码示例来源:origin: kite-sdk/kite

/**
 * Returns true if the end of input was hit by the search engine in the
 * last match operation performed by this matcher.
 *
 * @return true iff the end of input was hit in the last match; false otherwise
 */
public boolean hitEnd() {
  return matcher.hitEnd();
}

代码示例来源:origin: org.kitesdk/kite-morphlines-core

/**
 * Returns true if the end of input was hit by the search engine in the
 * last match operation performed by this matcher.
 *
 * @return true iff the end of input was hit in the last match; false otherwise
 */
public boolean hitEnd() {
  return matcher.hitEnd();
}

代码示例来源:origin: stackoverflow.com

Pattern thePattern = Pattern.compile(theRegexString);
Matcher m = thePattern.matcher(theStringToTest);
if (m.matches()) {
  return true;
}
return m.hitEnd();

代码示例来源:origin: stackoverflow.com

Pattern p = Pattern.compile("hello");
Matcher m = p.matcher("[a-z]");
System.out.println(m.hitEnd()); // prints false
System.out.println(m.find());  // prints false
System.out.println(m.hitEnd()); // prints true

代码示例来源:origin: stackoverflow.com

int farthestPoint(Pattern pattern, String input) {
  for (int i = input.length - 1; i > 0; i--) {
    Matcher matcher = pattern.matcher(input.substring(0, i));
    if (!matcher.matches() && matcher.hitEnd()) {
      return i;
    }
  }
  return 0;
}

代码示例来源:origin: stackoverflow.com

String input="AA";
Pattern pat=Pattern.compile("AAB");
Matcher matcher=pat.matcher(input);
System.out.println(matcher.matches()); // prints "false"
System.out.println(matcher.hitEnd());  // prints "true"

代码示例来源:origin: stackoverflow.com

if (textToParse != null) {
Matcher matcher = PLACEHOLDER_PATTERN.matcher(textToParse);
  while(matcher.hitEnd()!=true){
    Boolean result = matcher.find();
    int count = matcher.groupCount();
    System.out.println("Result " +result+" count "+count);
    if(result==true && count==1){
      mergeFieldName = matcher.group(1);
      mergeFieldNames.add(mergeFieldName);
      }
    }
 }

代码示例来源:origin: stackoverflow.com

Pattern p = Pattern.compile("^2(2[4-9]|3\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
 Matcher m = p.matcher("224..");
 if (!m.matches() && !m.hitEnd()) {
   System.out.println("Invalid");
 } else {
   System.out.println("Valid");
 }

代码示例来源:origin: stackoverflow.com

private final static Pattern WB_PATTERN = Pattern.compile("(?<=\\w)\\b");

private String truncateAfterWords(int n, String s) {
  if (s == null) return null;
  if (n <= 0) return "";
  Matcher m = WB_PATTERN.matcher(s);
  for (int i=0; i<n && m.find(); i++);
  if (m.hitEnd())
   return s;
  else
   return s.substring(0, m.end());
}

代码示例来源:origin: stackoverflow.com

String lString = "154540K->12341K(524288K)";
Pattern lPattern = Pattern.compile("\\d+");
Matcher lMatcher = lPattern.matcher(lString);

int lPosition = 2;
for (int i = 0; i < lPosition && lMatcher.find(); i++) {}

if (!lMatcher.hitEnd()) {
  System.out.println(lMatcher.group());
}

代码示例来源:origin: stackoverflow.com

String english = "Queen. of reptiles.";
Pattern p = Pattern.compile("\\w+|\\.");
Matcher m = p.matcher(english);

do {
  if (m.find()) {
   System.out.println(m.group());
  }
} while (!m.hitEnd());

代码示例来源:origin: stackoverflow.com

Pattern p = Pattern.compile("\\G[^,]*,|\\G[^,]+$");

String myCSV = "a,,b";
Matcher m = p.matcher(myCSV);

while (m.find()) {
  System.out.println("Match found from: " + m.start()
      + " (included) to: " + m.end() + " (excluded),"
      + " matching:  '" + m.group() + "'. Does it hit end?"
      + m.hitEnd());
}

代码示例来源:origin: stackoverflow.com

Matcher base = Pattern.compile("\\bred\\b|\\bgreen\\b|\\bblue\\b|[+()]{1}").matcher(input.trim());
while (!base.hitEnd()) {
  if (base.find()) {
   String s = base.group();
   System.out.println("Found: " + s);
   output += String.format(" %s", s);
  }
} 
if (output.isEmpty()) {
  throw new IllegalArgumentException("Invalid input no matching tokens found! " + base.toString());
}

相关文章