Skip to content

Instantly share code, notes, and snippets.

@Vishal023
Last active July 22, 2020 06:02
Show Gist options
  • Save Vishal023/735c164846fd1fa4541a9f82240e23e1 to your computer and use it in GitHub Desktop.
Save Vishal023/735c164846fd1fa4541a9f82240e23e1 to your computer and use it in GitHub Desktop.
Java Regex

REGEX

REGEX EXPRESSION PATTERN

EXPRESSION DESCRIPTION
[ABC] Find one character from the options between the brackets
[^ABC] Find one character NOT from the options between the brackets
[0-9] Find one character from the range 0 to 9
[a-g] Character between a & g

METACHARACTERS

METACHARACTERS DESCRIPTION
| Find a match for any one of the patterns separated by | as in: cat|dog|fish
. Find just one instance of any character
^ Finds a match as the beginning of a string as in: ^Hello
$ Finds a match at the end of the string as in: World$
\d Find a digit
\s Find a whitespace character
\b Find a match at the beginning of a word like this: \bWORD, or at the end of a word like this: WORD\b
\uxxxx Find the Unicode character specified by the hexadecimal number xxxx

QUANTIFIERS

Quantifier Description
n+ Matches any string that contains at least one
n* Matches any string that contains zero or more occurrences of n
n? Matches any string that contains zero or one occurrences of n
n{x} Matches any string that contains a sequence of X n's
n{x,y} Matches any string that contains a sequence of X to Y n's
n{x,} Matches any string that contains a sequence of at least X n's
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment