code: public static ExpectedCondition<Boolean> textMatches(final By locator, final Pattern pattern) {
      return new ExpectedCondition<Boolean>() {
        private String currentValue = null;
  
        @Override
        public Boolean apply(WebDriver driver) {
          try {
            currentValue = driver.findElement(locator).getText();
            return pattern.matcher(currentValue).find();
          } catch (Exception e) {
            return false;
          }
        }
  
        @Override
        public String toString() {
          return String
            .format("text found by %s to match pattern \"%s\". Current text: \"%s\"",
                    locator, pattern.pattern(), currentValue);
        }
      };
    }
docs: An expectation for checking WebElement with given locator has text with a value as a part of
  it
  
  @param locator used to find the element
  @param pattern used as expected text matcher pattern
  @return Boolean true when element has text value containing @value