matches

infix fun matches(text: CharSequence): Boolean

Returns true if the specified text matches this regular expression, or returns false otherwise.


Calling from Kotlin

Here's an example of calling this function from Kotlin code:

val text = "contact@kotools.org"
val regex: EmailAddressRegex = EmailAddressRegex.alphabetic()
val result: Boolean = regex.matches(text)
val message =
    "'$text' matches the following regular expression: '$regex'."
assertTrue(result, message)

Calling from Java

Here's an example of calling this function from Java code:

final String text = "contact@kotools.org";
final EmailAddressRegex regex = EmailAddressRegex.alphabetic();
final boolean result = regex.matches(text);
final String message = String.format(
        "'%s' matches the following regular expression: '%s'.",
        text,
        regex
);
Assertions.assertTrue(result, message);