Stay organized with collections
Save and categorize content based on your preferences.
java.util.regex
Classes for matching character sequences against patterns specified
by regular expressions.
An instance of the Pattern
class
represents a regular expression that is specified in string form in
a syntax similar to that used by Perl.
Instances of the Matcher
class are used
to match character sequences against a given pattern. Input is
provided to matchers via the CharSequence
interface in order to support matching against characters from a
wide variety of input sources.
Unless otherwise noted, passing a null
argument to a
method in any class or interface in this package will cause a
NullPointerException
to be
thrown.
An excellent tutorial and overview of regular expressions is Mastering Regular
Expressions, Jeffrey E. F. Friedl, O'Reilly and Associates,
1997.
Interfaces
Classes
Exceptions
Interfaces
Classes
Exceptions
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# java.util.regex\n\nAdded in [API level 1](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\njava.util.regex\n===============\n\nClasses for matching character sequences against patterns specified by regular expressions.\n\nAn instance of the [Pattern](/reference/java/util/regex/Pattern) class\nrepresents a regular expression that is specified in string form in\na syntax similar to that used by Perl.\n\nInstances of the [Matcher](/reference/java/util/regex/Matcher) class are used\nto match character sequences against a given pattern. Input is\nprovided to matchers via the [CharSequence](/reference/java/lang/CharSequence)\ninterface in order to support matching against characters from a\nwide variety of input sources.\n\nUnless otherwise noted, passing a `null` argument to a\nmethod in any class or interface in this package will cause a\n[NullPointerException](/reference/java/lang/NullPointerException) to be\nthrown.\n\nRelated Documentation\n---------------------\n\nAn excellent tutorial and overview of regular expressions is [*Mastering Regular\nExpressions*, Jeffrey E. F. Friedl, O'Reilly and Associates,\n1997.](http://www.oreilly.com/catalog/regex/)\n\nInterfaces\n----------\n\n|-------------------------------------------------------|----------------------------------|\n| [MatchResult](/reference/java/util/regex/MatchResult) | The result of a match operation. |\n\nClasses\n-------\n\n|-----------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [Matcher](/reference/java/util/regex/Matcher) | An engine that performs match operations on a [character sequence](/reference/java/lang/CharSequence) by interpreting a [Pattern](/reference/java/util/regex/Pattern). |\n| [Pattern](/reference/java/util/regex/Pattern) | A compiled representation of a regular expression. |\n\nExceptions\n----------\n\n|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------|\n| [PatternSyntaxException](/reference/java/util/regex/PatternSyntaxException) | Unchecked exception thrown to indicate a syntax error in a regular-expression pattern. |\n\n-\n\n Interfaces\n ----------\n\n - [MatchResult](/reference/java/util/regex/MatchResult)\n-\n\n Classes\n -------\n\n - [Matcher](/reference/java/util/regex/Matcher)\n - [Pattern](/reference/java/util/regex/Pattern)\n-\n\n Exceptions\n ----------\n\n - [PatternSyntaxException](/reference/java/util/regex/PatternSyntaxException)"]]