public final class

Patterns

extends java.lang.Object

 java.lang.Object

↳androidx.test.uiautomator.util.Patterns

Gradle dependencies

compile group: 'androidx.test.uiautomator', name: 'uiautomator', version: '2.4.0-alpha01'

  • groupId: androidx.test.uiautomator
  • artifactId: uiautomator
  • version: 2.4.0-alpha01

Artifact androidx.test.uiautomator:uiautomator:2.4.0-alpha01 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.test.uiautomator:uiautomator com.android.support.test.uiautomator:uiautomator

Overview

Static regex utilities.

Summary

Methods
public static java.util.regex.Patterncontains(java.lang.String text)

Returns a java.util.regex.Pattern that matches when content contains given string (case-sensitive).

public static java.util.regex.PatternendsWith(java.lang.String text)

Returns a java.util.regex.Pattern that matches when content ends with given string (case-sensitive).

public static java.util.regex.PatternstartsWith(java.lang.String text)

Returns a java.util.regex.Pattern that matches when content starts with given string (case-sensitive).

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Methods

public static java.util.regex.Pattern startsWith(java.lang.String text)

Returns a java.util.regex.Pattern that matches when content starts with given string (case-sensitive).

public static java.util.regex.Pattern endsWith(java.lang.String text)

Returns a java.util.regex.Pattern that matches when content ends with given string (case-sensitive).

public static java.util.regex.Pattern contains(java.lang.String text)

Returns a java.util.regex.Pattern that matches when content contains given string (case-sensitive).

Source

/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.test.uiautomator.util;

import androidx.annotation.NonNull;
import androidx.annotation.RestrictTo;

import java.util.regex.Pattern;

/** Static regex utilities. */
@RestrictTo(RestrictTo.Scope.LIBRARY)
public final class Patterns {

    private Patterns() {}

    /**
     * Returns a {@link Pattern} that matches when content starts with given string
     * (case-sensitive).
     */
    @NonNull
    public static Pattern startsWith(@NonNull String text) {
        return Pattern.compile(String.format("^%s.*$", Pattern.quote(text)), Pattern.DOTALL);
    }

    /**
     * Returns a {@link Pattern} that matches when content ends with given string
     * (case-sensitive).
     */
    @NonNull
    public static Pattern endsWith(@NonNull String text) {
        return Pattern.compile(String.format("^.*%s$", Pattern.quote(text)), Pattern.DOTALL);
    }

    /**
     * Returns a {@link Pattern} that matches when content contains given string (case-sensitive).
     */
    @NonNull
    public static Pattern contains(@NonNull String text) {
        return Pattern.compile(String.format("^.*%s.*$", Pattern.quote(text)), Pattern.DOTALL);
    }
}