Tabnine Logo
Pattern.matcher
Code IndexAdd Tabnine to your IDE (free)

How to use
matcher
method
in
java.util.regex.Pattern

Best Java code snippets using java.util.regex.Pattern.matcher (Showing top 20 results out of 120,573)

Refine searchRefine arrow

  • Matcher.group
  • Matcher.find
  • Pattern.compile
  • Matcher.matches
  • PrintStream.println
origin: spring-projects/spring-framework

/**
 * Returns {@code true} if the exclusion {@link Pattern} at index {@code patternIndex}
 * matches the supplied candidate {@code String}.
 */
@Override
protected boolean matchesExclusion(String candidate, int patternIndex) {
  Matcher matcher = this.compiledExclusionPatterns[patternIndex].matcher(candidate);
  return matcher.matches();
}
origin: square/retrofit

/**
 * Gets the set of unique path parameters used in the given URI. If a parameter is used twice
 * in the URI, it will only show up once in the set.
 */
static Set<String> parsePathParameters(String path) {
 Matcher m = PARAM_URL_REGEX.matcher(path);
 Set<String> patterns = new LinkedHashSet<>();
 while (m.find()) {
  patterns.add(m.group(1));
 }
 return patterns;
}
origin: stackoverflow.com

 String mydata = "some string with 'the data i want' inside";
Pattern pattern = Pattern.compile("'(.*?)'");
Matcher matcher = pattern.matcher(mydata);
if (matcher.find())
{
  System.out.println(matcher.group(1));
}
origin: apache/kafka

/**
 * Extracts the hostname from a "host:port" address string.
 * @param address address string to parse
 * @return hostname or null if the given address is incorrect
 */
public static String getHost(String address) {
  Matcher matcher = HOST_PORT_PATTERN.matcher(address);
  return matcher.matches() ? matcher.group(1) : null;
}
origin: org.mockito/mockito-core

static boolean isJava8BelowUpdate45(String jvmVersion) {
  Matcher matcher = JAVA_8_RELEASE_VERSION_SCHEME.matcher(jvmVersion);
  if (matcher.matches()) {
    int update = Integer.parseInt(matcher.group(1));
    return update < 45;
  }
  matcher = JAVA_8_DEV_VERSION_SCHEME.matcher(jvmVersion);
  if (matcher.matches()) {
    int update = Integer.parseInt(matcher.group(1));
    return update < 45;
  }
  matcher = Pattern.compile("1\\.8\\.0-b\\d+").matcher(jvmVersion);
  return matcher.matches();
}
origin: jenkinsci/jenkins

/**
 * See {@link hudson.FilePath#isAbsolute(String)}.
 * @param path String representing <code> Platform Specific </code> (unlike FilePath, which may get Platform agnostic paths), may not be null
 * @return true if String represents absolute path on this platform, false otherwise
 */
public static boolean isAbsolute(String path) {
  Pattern DRIVE_PATTERN = Pattern.compile("[A-Za-z]:[\\\\/].*");
  return path.startsWith("/") || DRIVE_PATTERN.matcher(path).matches();
}
origin: spring-projects/spring-framework

private void assertDescriptionContainsExpectedPath(ClassPathResource resource, String expectedPath) {
  Matcher matcher = DESCRIPTION_PATTERN.matcher(resource.getDescription());
  assertTrue(matcher.matches());
  assertEquals(1, matcher.groupCount());
  String match = matcher.group(1);
  assertEquals(expectedPath, match);
}
origin: google/guava

/**
 * Returns a new {@code MatchResult} that corresponds to a successful match. Apache Harmony (used
 * in Android) requires a successful match in order to generate a {@code MatchResult}:
 * http://goo.gl/5VQFmC
 */
private static MatchResult newMatchResult() {
 Matcher matcher = Pattern.compile(".").matcher("X");
 matcher.find();
 return matcher.toMatchResult();
}
origin: stackoverflow.com

 Pattern p = Pattern.compile("^[a-zA-Z]+([0-9]+).*");
Matcher m = p.matcher("Testing123Testing");

if (m.find()) {
  System.out.println(m.group(1));
}
origin: apache/kafka

/**
 * Extracts the port number from a "host:port" address string.
 * @param address address string to parse
 * @return port number or null if the given address is incorrect
 */
public static Integer getPort(String address) {
  Matcher matcher = HOST_PORT_PATTERN.matcher(address);
  return matcher.matches() ? Integer.parseInt(matcher.group(2)) : null;
}
origin: spring-projects/spring-framework

/**
 * Returns {@code true} if the {@link Pattern} at index {@code patternIndex}
 * matches the supplied candidate {@code String}.
 */
@Override
protected boolean matches(String pattern, int patternIndex) {
  Matcher matcher = this.compiledPatterns[patternIndex].matcher(pattern);
  return matcher.matches();
}
origin: Netflix/eureka

  private static String resolveJarUrl(Class<?> clazz) {
    URL location = clazz.getResource('/' + clazz.getName().replace('.', '/') + ".class");
    if (location != null) {
      Matcher matcher = Pattern.compile("(jar:file.*-[\\d.]+(-rc[\\d]+|-SNAPSHOT)?.jar)!.*$").matcher(location.toString());
      if (matcher.matches()) {
        return matcher.group(1);
      }
    }
    return null;
  }
}
origin: spring-projects/spring-framework

@Override
public String extractVersion(String requestPath) {
  Matcher matcher = pattern.matcher(requestPath);
  if (matcher.find()) {
    String match = matcher.group(1);
    return (match.contains("-") ? match.substring(match.lastIndexOf('-') + 1) : match);
  }
  else {
    return null;
  }
}
origin: libgdx/libgdx

/**
 * @return {@code true} if application runs on a mobile device
 */
public static boolean isMobileDevice() {
  // RegEx pattern from detectmobilebrowsers.com (public domain)
  String pattern = "(android|bb\\d+|meego).+mobile|avantgo|bada\\/|blackberry|blazer|compal|elaine|fennec" +
      "|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)" +
      "i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\\.(browser|link)" +
      "|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk";
  Pattern p = Pattern.compile(pattern);
  Matcher m = p.matcher(Window.Navigator.getUserAgent().toLowerCase());
  return m.matches();
}
origin: google/guava

 private static void assertContainsRegex(String expectedRegex, String actual) {
  Pattern pattern = Pattern.compile(expectedRegex);
  Matcher matcher = pattern.matcher(actual);
  if (!matcher.find()) {
   String actualDesc = (actual == null) ? "null" : ('<' + actual + '>');
   fail("expected to contain regex:<" + expectedRegex + "> but was:" + actualDesc);
  }
 }
}
origin: libgdx/libgdx

private String getError (String line) {
  Pattern pattern = Pattern.compile(":[0-9]+:[0-9]+:(.+)");
  Matcher matcher = pattern.matcher(line);
  matcher.find();
  return matcher.groupCount() >= 1 ? matcher.group(1).trim() : null;
}
origin: Netflix/eureka

public static String extractZoneFromHostName(String hostName) {
  Matcher matcher = ZONE_RE.matcher(hostName);
  if (matcher.matches()) {
    return matcher.group(2);
  }
  return null;
}
origin: square/okhttp

/** Returns true if {@code host} is not a host name and might be an IP address. */
public static boolean verifyAsIpAddress(String host) {
 return VERIFY_AS_IP_ADDRESS.matcher(host).matches();
}
origin: Netflix/eureka

private void handleInstanceGET(HttpExchange httpExchange) throws IOException {
  Matcher matcher = Pattern.compile("/v2/instances/([^/]+)").matcher(httpExchange.getRequestURI().getPath());
  if (matcher.matches()) {
    mapResponse(httpExchange, requestHandler.getInstance(matcher.group(1)));
  } else {
    httpExchange.sendResponseHeaders(HttpServletResponse.SC_NOT_FOUND, 0);
  }
}
origin: spring-projects/spring-framework

@Override
@Nullable
public String extractVersion(String requestPath) {
  Matcher matcher = pattern.matcher(requestPath);
  if (matcher.find()) {
    String match = matcher.group(1);
    return (match.contains("-") ? match.substring(match.lastIndexOf('-') + 1) : match);
  }
  else {
    return null;
  }
}
java.util.regexPatternmatcher

Javadoc

Returns a Matcher for this pattern applied to the given input. The Matcher can be used to match the Pattern against the whole input, find occurrences of the Pattern in the input, or replace parts of the input.

Popular methods of Pattern

  • compile
    Compiles the given regular expression into a pattern with the given flags.
  • quote
    Returns a literal pattern String for the specifiedString.This method produces a String that can be u
  • split
    Splits the given input sequence around matches of this pattern. The array returned by this method co
  • pattern
  • matches
    Compiles the given regular expression and attempts to match the given input against it. An invocatio
  • toString
    Returns the string representation of this pattern. This is the regular expression from which this pa
  • flags
    Returns this pattern's match flags.
  • splitAsStream
  • asPredicate
  • <init>
    This private constructor is used to create all Patterns. The pattern string and match flags are all
  • closeImpl
  • compileImpl
  • closeImpl,
  • compileImpl,
  • closure,
  • error,
  • escape,
  • RemoveQEQuoting,
  • accept,
  • addFlag,
  • append

Popular in Java

  • Making http requests using okhttp
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • onRequestPermissionsResult (Fragment)
  • startActivity (Activity)
  • FileWriter (java.io)
    A specialized Writer that writes to a file in the file system. All write requests made by calling me
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • ThreadPoolExecutor (java.util.concurrent)
    An ExecutorService that executes each submitted task using one of possibly several pooled threads, n
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Logger (org.slf4j)
    The org.slf4j.Logger interface is the main user entry point of SLF4J API. It is expected that loggin
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now