0% found this document useful (0 votes)
484 views

Regular Expressions Cheat Sheet PDF

This document provides a cheat sheet for regular expressions (regex) in Java. It outlines various regex constructs including character classes, quantifiers, boundary matches, groups and backreferences, and logical operations. It also summarizes useful Java classes and methods for working with regex like the Pattern and Matcher classes.

Uploaded by

sagiba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
484 views

Regular Expressions Cheat Sheet PDF

This document provides a cheat sheet for regular expressions (regex) in Java. It outlines various regex constructs including character classes, quantifiers, boundary matches, groups and backreferences, and logical operations. It also summarizes useful Java classes and methods for working with regex like the Pattern and Matcher classes.

Uploaded by

sagiba
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Regex Cheat Sheet

CHARACTER CLASSES USEFUL JAVA CLASSES & METHODS QUANTIFIERS


[abc] Matches a or b, or c. PATTERN Greedy Reluctant Possessive Description
[^abc] Negation, matches everything except a, b, or c. A pattern is a compiler representation of a regular expression.
[a-c] Range, matches a or b, or c. X? X?? X?+ X, once or not at
[a-c[f-h]] Union, matches a, b, c, f, g, h. Pattern compile(String regex) all.
Compiles the given regular expression into a pattern. X, zero or more
[a-c&&[b-c]] Intersection, matches b or c. X* X*? X*+ times.
[a-c&&[^b-c]] Subtraction, matches a. Pattern compile(String regex, int flags) X, one or more
X+ X+? X++
Compiles the given regular expression into a pattern times.
PREDEFINED CHARACTER CLASSES with the given flags.
X{n} X{n}? X{n}+ X, exactly n times.
. Any character. boolean matches(String regex)
\d A digit: [0-9] Tells whether or not this string matches the given X{n,} X{n,}? X{n,}+ X, at least n times.
\D A non-digit: [^0-9] regular expression. X, at least n but
\s A whitespace character: [ \t\n\x0B\f\r] X{n,m} X{n,m}? X{n,m}+ not more than m
String[] split(CharSequence input) times.
\S A non-whitespace character: [^\s] Splits the given input sequence around matches of
\w A word character: [a-zA-Z_0-9] this pattern.
\W A non-word character: [^\w] Greedy Matches the longest matching group.
String quote(String s) Reluctant Matches the shortest group.
BOUNDARY MATCHES Returns a literal pattern String for the specified String. Possessive Longest match or bust (no backoff).

Predicate<String> asPredicate()
^ The beginning of a line.
Creates a predicate which can be used to match a string. GROUPS & BACKREFERENCES
$ The end of a line.
\b A word boundary. A group is a captured subsequence of characters which may
MATCHER be used later in the expression with a backreference.
\B A non-word boundary.
\A The beginning of the input. An engine that performs match operations on a character
sequence by interpreting a pattern. (...) Defines a group.
\G The end of the previous match. \N Refers to a matched group.
\Z The end of the input but for the final terminator, if any. boolean matches() (\d\d) A group of two digits.
\z The end of the input. Attempts to match the entire region against the pattern. (\d\d)/\1 Two digits repeated twice.
\1 Refers to the matched group.
boolean find()
PATTERN FLAGS Attempts to find the next subsequence of the input
Pattern.CASE_INSENSITIVE sequence that matches the pattern.
Enables case-insensitive matching. LOGICAL OPERATIONS
int start()
Pattern.COMMENTS XY X then Y.
Returns the start index of the previous match.
Whitespace and comments starting with # are ignored until the X|Y X or Y.
end of a line. int end()
Pattern.MULTILINE Returns the offset after the last character matched.
One expression can match multiple lines.
Pattern.UNIX_LINES LEARN HOW JREBEL AND XREBEL TRANSFORM
Only the '\n' line terminator is recognized in the behavior of ., ^, ENTERPRISE SOFTWARE DEVELOPMENT.
and $. Try for free at jrebel.com

www.jrebel.com

You might also like