Codota Logo
Pattern.pattern
Code IndexAdd Codota to your IDE (free)

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

Best Java code snippets using java.util.regex.Pattern.pattern (Showing top 20 results out of 8,946)

Refine searchRefine arrow

  • Matcher.matches
  • Pattern.matcher
  • Pattern.compile
  • Pattern.flags
  • Common ways to obtain Pattern
private void myMethod () {
Pattern p =
  • Codota IconString regex;Pattern.compile(regex)
  • Codota IconString regex;Pattern.compile(regex, flags)
  • Codota IconStringBuffer regex;Pattern.compile(regex.toString())
  • Smart code suggestions by Codota
}
origin: square/retrofit

private void validatePathName(int p, String name) {
 if (!PARAM_NAME_REGEX.matcher(name).matches()) {
  throw parameterError(method, p, "@Path parameter name must match %s. Found: %s",
    PARAM_URL_REGEX.pattern(), name);
 }
 // Verify URL replacement name is actually present in the URL path.
 if (!relativeUrlParamNames.contains(name)) {
  throw parameterError(method, p, "URL \"%s\" does not contain \"{%s}\".", relativeUrl, name);
 }
}
origin: FudanNLP/fnlp

private Pattern readModel(ObjectInputStream in) throws Exception {
  Pattern p = (Pattern) in.readObject();
  //System.out.print(p.pattern());
  return p=Pattern.compile(p.pattern());
}
 
origin: apache/incubator-shardingsphere

public PostgreSQLDataSourceMetaData(final String url) {
  Matcher matcher = pattern.matcher(url);
  if (matcher.find()) {
    hostName = matcher.group(1);
    port = Strings.isNullOrEmpty(matcher.group(2)) ? DEFAULT_PORT : Integer.valueOf(matcher.group(2));
    schemaName = matcher.group(3);
  } else {
    throw new ShardingException("The URL of JDBC is not supported. Please refer to this pattern: %s.", pattern.pattern());
  }
}
origin: languagetool-org/languagetool

Pattern pattern = Pattern.compile(args.get("regexp"));
String requiredTagRegexp = args.get("postag_regexp");
boolean negatePos = args.containsKey("negate_pos");
boolean two_groups_regexp = args.containsKey("two_groups_regexp");
String token = patternTokens[tokenPos - 1].getToken();
Matcher matcher = pattern.matcher(token);
if ((matcher.groupCount() != 1) && !(two_groups_regexp)) {
 throw new RuntimeException("Got " + matcher.groupCount() + " groups for regex '" + pattern.pattern() + "', expected 1");
 throw new RuntimeException("Got " + matcher.groupCount() + " groups for regex '" + pattern.pattern() + "', expected 2");
if (matcher.matches()) {
 String partialToken = matcher.group(1);
 if (matcher.groupCount() == 2) {
origin: apache/flume

@Override
public void configure(Context context) {
 String regexString = context.getString(REGEX);
 Preconditions.checkArgument(!StringUtils.isEmpty(regexString),
   "Must supply a valid regex string");
 regex = Pattern.compile(regexString);
 regex.pattern();
 regex.matcher("").groupCount();
 configureSerializers(context);
}
origin: google/guava

@GwtIncompatible // Doubles.tryParse
private static void checkTryParse(double expected, String input) {
 assertEquals(Double.valueOf(expected), Doubles.tryParse(input));
 assertThat(input)
   .matches(
     Pattern.compile(
       Doubles.FLOATING_POINT_PATTERN.pattern(), Doubles.FLOATING_POINT_PATTERN.flags()));
}
origin: apache/geode

private void writeGraphName(Object graphName) throws IOException {
 boolean isPattern = graphName instanceof Pattern;
 outputStream.writeBoolean(isPattern);
 if (isPattern) {
  final Pattern pattern = (Pattern) graphName;
  outputStream.writeUTF(pattern.pattern());
  outputStream.writeInt(pattern.flags());
 } else {
  outputStream.writeUTF(graphName.toString());
 }
}
origin: org.testng/testng

private static Boolean isMatch(Pattern pattern, String group) {
 Pair<String, String> cacheKey = Pair.create(pattern.pattern(), group);
 Boolean match = MATCH_CACHE.get(cacheKey);
 if (match == null) {
  match = pattern.matcher(group).matches();
  MATCH_CACHE.put(cacheKey, match);
 }
 return match;
}
origin: RipMeApp/ripme

@Override
public String getAlbumTitle(URL url) throws MalformedURLException {
  try {
    // Attempt to use album title as GID
    Elements elems = getFirstPage().select("legend");
    String title = elems.first().text();
    LOGGER.info("Title text: '" + title + "'");
    Pattern p = Pattern.compile("^(.*)\\s\\d* image.*$");
    Matcher m = p.matcher(title);
    if (m.matches()) {
      return getHost() + "_" + getGID(url) + " (" + m.group(1).trim() + ")";
    }
    LOGGER.info("Doesn't match " + p.pattern());
  } catch (Exception e) {
    // Fall back to default album naming convention
    LOGGER.warn("Failed to get album title from " + url, e);
  }
  return super.getAlbumTitle(url);
}
origin: groovy/groovy-core

private void initialize() {
  matcher = null;
  groupList.clear();
  groupList.add(null);
  
  Iterator iter = styleMap.keySet().iterator();
  String regexp = "";
  while (iter.hasNext()) {
    String nextRegexp = (String)iter.next();
    regexp += "|(" + nextRegexp + ")";
    // have to compile regexp first so that it will match
    groupList.add(Pattern.compile(nextRegexp).pattern());
  }
  if (!regexp.equals("")) {
    matcher = Pattern.compile(regexp.substring(1)).matcher("");
    
    iter = children.values().iterator();
    while (iter.hasNext()) {
      ((LexerNode)iter.next()).initialize();
    }
  }
  initialized = true;
}

origin: apache/incubator-shardingsphere

public H2DataSourceMetaData(final String url) {
  Matcher matcher = pattern.matcher(url);
  if (matcher.find()) {
    hostName = matcher.group(1);
    port = DEFAULT_PORT;
    schemaName = matcher.group(2);
  } else {
    throw new ShardingException("The URL of JDBC is not supported. Please refer to this pattern: %s.", pattern.pattern());
  }
}

origin: groovy/groovy-core

/**
 *
 * @param regexp
 * @param node
 */        
public void putChild(String regexp, LexerNode node) {
  node.defaultStyle = (Style)styleMap.get(regexp);
  
  // have to compile regexp first so that it will match
  children.put(Pattern.compile(regexp).pattern(), node);
  initialized = false;
}
origin: google/guava

@GwtIncompatible // Doubles.tryParse
public void testTryParseFailures() {
 for (String badInput : BAD_TRY_PARSE_INPUTS) {
  assertThat(badInput)
    .doesNotMatch(
      Pattern.compile(
        Doubles.FLOATING_POINT_PATTERN.pattern(),
        Doubles.FLOATING_POINT_PATTERN.flags()));
  assertEquals(referenceTryParse(badInput), Doubles.tryParse(badInput));
  assertNull(Doubles.tryParse(badInput));
 }
}
origin: json-path/JsonPath

PatternNode(Pattern pattern) {
  this.pattern = pattern.pattern();
  this.compiledPattern = pattern;
  this.flags = PatternFlag.parseFlags(pattern.flags());
}
origin: apache/kafka

String apply(String distinguishedName) {
  if (isDefault) {
    return distinguishedName;
  }
  String result = null;
  final Matcher m = pattern.matcher(distinguishedName);
  if (m.matches()) {
    result = distinguishedName.replaceAll(pattern.pattern(), escapeLiteralBackReferences(replacement, m.groupCount()));
  }
  if (toLowerCase && result != null) {
    result = result.toLowerCase(Locale.ENGLISH);
  } else if (toUpperCase & result != null) {
    result = result.toUpperCase(Locale.ENGLISH);
  }
  return result;
}
origin: cloudfoundry/uaa

  public static void validate(final ScimUser user) throws InvalidScimResourceException {
    Pattern usernamePattern = Pattern.compile("[\\p{L}+0-9+\\-_.@'!]+");
    if (!hasText(user.getUserName())) {
      throw new InvalidScimResourceException("A username must be provided.");
    }
    if (OriginKeys.UAA.equals(user.getOrigin()) && !usernamePattern.matcher(user.getUserName()).matches()) {
      throw new InvalidScimResourceException("Username must match pattern: " + usernamePattern.pattern());
    }
    if (user.getEmails() == null || user.getEmails().size() != 1) {
      throw new InvalidScimResourceException("Exactly one email must be provided.");
    }
    for (ScimUser.Email email : user.getEmails()) {
      if (email == null || email.getValue() == null || email.getValue().isEmpty()) {
        throw new InvalidScimResourceException("An email must be provided.");
      }
    }
  }
}
origin: org.assertj/assertj-core

/**
 * Verifies that the given {@code CharSequence} contains the given regular expression.
 *
 * @param info contains information about the assertion.
 * @param actual the given {@code CharSequence}.
 * @param regex the regular expression to find in the actual {@code CharSequence}.
 * @throws NullPointerException if the given pattern is {@code null}.
 * @throws PatternSyntaxException if the regular expression's syntax is invalid.
 * @throws AssertionError if the given {@code CharSequence} is {@code null}.
 * @throws AssertionError if the actual {@code CharSequence} does not contain the given regular expression.
 */
public void assertContainsPattern(AssertionInfo info, CharSequence actual, CharSequence regex) {
 checkRegexIsNotNull(regex);
 assertNotNull(info, actual);
 Pattern pattern = Pattern.compile(regex.toString());
 Matcher matcher = pattern.matcher(actual);
 if (!matcher.find()) throw failures.failure(info, shouldContainPattern(actual, pattern.pattern()));
}
origin: apache/incubator-shardingsphere

public OracleDataSourceMetaData(final String url) {
  Matcher matcher = pattern.matcher(url);
  if (matcher.find()) {
    hostName = matcher.group(1);
    port = Strings.isNullOrEmpty(matcher.group(2)) ? DEFAULT_PORT : Integer.valueOf(matcher.group(2));
    schemaName = matcher.group(3);
  } else {
    throw new ShardingException("The URL of JDBC is not supported. Please refer to this pattern: %s.", pattern.pattern());
  }
}

origin: google/guava

public void testGet_regex() {
 assertEquals(Pattern.compile("").pattern(), ArbitraryInstances.get(Pattern.class).pattern());
 assertEquals(0, ArbitraryInstances.get(MatchResult.class).groupCount());
}
origin: spring-projects/spring-data-mongodb

/**
 * Checks the given objects for equality. Handles {@link Pattern} and arrays correctly.
 *
 * @param left
 * @param right
 * @return
 */
private boolean isEqual(Object left, Object right) {
  if (left == null) {
    return right == null;
  }
  if (Pattern.class.isInstance(left)) {
    if (!Pattern.class.isInstance(right)) {
      return false;
    }
    Pattern leftPattern = (Pattern) left;
    Pattern rightPattern = (Pattern) right;
    return leftPattern.pattern().equals(rightPattern.pattern()) //
        && leftPattern.flags() == rightPattern.flags();
  }
  return ObjectUtils.nullSafeEquals(left, right);
}
java.util.regexPatternpattern

Javadoc

The original regular-expression pattern string.

Popular methods of Pattern

  • matcher
    Creates a matcher that will match the given input against this 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
  • 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

  • Updating database using SQL prepared statement
  • startActivity (Activity)
  • addToBackStack (FragmentTransaction)
  • notifyDataSetChanged (ArrayAdapter)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • FileOutputStream (java.io)
    A file output stream is an output stream for writing data to aFile or to a FileDescriptor. Whether
  • BigInteger (java.math)
    Immutable arbitrary-precision integers. All operations behave as if BigIntegers were represented in
  • InetAddress (java.net)
    This class represents an Internet Protocol (IP) address. An IP address is either a 32-bit or 128-bit
  • Locale (java.util)
    A Locale object represents a specific geographical, political, or cultural region. An operation that
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registery of org.quartz
Codota Logo
  • Products

    Search for Java codeSearch for JavaScript codeEnterprise
  • IDE Plugins

    IntelliJ IDEAWebStormAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogCodota Academy Plugin user guide Terms of usePrivacy policyJava Code IndexJavascript Code Index
Get Codota for your IDE now