Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

The complete RegEx Cheat Sheet, Cheat Sheet of Java Programming

This document contains a quick overview with the main RegEx notions.

Typology: Cheat Sheet

2019/2020

Uploaded on 10/09/2020

amoda
amoda ๐Ÿ‡บ๐Ÿ‡ธ

4.1

(13)

257 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
The complete RegEx Cheat Sheet
by doublehelix via cheatography.com/27391/cs/7932/
Anchors (bound๎˜aries)
^ Start of string or line
$ End of string or line
\A Start of input (ignores 'm' flag)
\Z End of input (ignores 'm' flag)
\G End of the previous match
\b Word bo undary (any position proceeded or followed - but not both -
by a letter, digit or unders๎˜core)
\B Non-word boundary
Character and Sets
\w Word [a-zA-๎˜Z0-9_]
\W Non-word [^a-zA๎˜-Z0-9_]
\d Digit [0-9]
\D Non-digit
\s Whitespace (Form-๎˜feed, tab, vertic๎˜al-tab, new
line, carriage return and space)
[\f\t๎˜\x0b\n\r ]
\S Non-wh๎˜ite๎˜space
\x Hexade๎˜cimal digit \x00=null; \x0d=\r;
[\x61-๎˜\x7๎˜a]=๎˜[a-z]
\O Octal digit
. Any character (except new line \n)
Groups
(...) Capture group - captures a set of characters for a later
expression
(?:...) Non-ca๎˜pture group - groups an expression but does not capture.
e.g. /((?:f๎˜oo|๎˜fu)๎˜bar)/ matches "๎˜foo๎˜bar๎˜" or "๎˜fub๎˜ar" without "๎˜foo๎˜" or
"๎˜fu" appearing as a captured subpattern
(?
=...)
Lookahead - match on the characters following. e.g. /ab(?= c)/
match "๎˜ab" only when followed by "๎˜c"
(?!...) Negative lookahead - match on characters that aren't following .
e.g. /ab(?!c)/ match "๎˜ab" only when NOT followed by "๎˜c"
(?
<๎˜=...)
Positive look-b๎˜ehind assertion. e.g. /(?<=f๎˜oo)bar/ matches " ๎˜bar๎˜"
when preceded by "๎˜foo๎˜"
(?
<๎˜!...)
Negative look-b๎˜ehind assertion. e.g. /(?<!f๎˜oo)bar/ - matches "๎˜bar๎˜"
when not preceded by "๎˜foo๎˜"
(?
#...)
Comment e.g. (?# This comment is ignored entirely)
Unicode character support
\x0000๎˜-\xFFFF Unicode hexade๎˜cimal character set
\x00-\xFF ASCII hexade๎˜cimal character set
\cA-\cZ Control characters
Unicode is not fully supported on all platforms. JavaScript prio r to ES6 for
example allows ASCII hex but not full Unicode hex.
Special Characters
\n New line
\r Carriage return
\t Tab
\v Vertical tab
\f Form feed
Quanti๎˜fiers
* Zero or more
+ One or more
? Zero or One (i.e. optional)
{n} Exactly 'n' (any number)
{n,} Minimum ('n' or more)
{n,m} Range ('n' or more, but less or equal to 'm')
Flags (expre๎˜ssion modifiers)
/m Milti-๎˜line. (Makes ^ and $ match the start and end of a line
respec๎˜tively)
/s Treat input as a single line. (Makes '.' match new lines as we ll)
/i Case insens๎˜itive p attern matching.
/g Global matching . (Don't stop after first match in a replac๎˜ement
function)
/x Extended matching. (disregard white-๎˜space not explicitly esca ped,
and allow comments starting with #)
Escape Characters
In regular expres๎˜sions, the following characters have special m eaning and
must be escaped: ^ $ [ { ( ) < > . * \ + | ?
Additi๎˜onally the hyphen (-) and close square bracket (]) must be escaped
when in an expression set ([...]).
e.g. /\(\d๎˜{3}\) \d{4}[\- ]\d{4}/ matches "๎˜(nnn) nnnn-n๎˜nnn๎˜" or
"๎˜(nnn) nnnn nnnn" (where n is a numeric digit).
By doublehelix
cheatography.com/doublehelix/
Published 30th January, 2017.
Last updated 31st January, 2017.
Page 1 of 1.
Sponsored by Readability-Score.com
Measure your website readability!
https://readability-score.com

Partial preview of the text

Download The complete RegEx Cheat Sheet and more Cheat Sheet Java Programming in PDF only on Docsity!

The complete RegEx Cheat Sheet

by doublehelix via cheatography.com/27391/cs/7932/

Anchors (boundaries) ^ Start of string or line $ End of string or line \A Start of input (ignores 'm' flag) \Z End of input (ignores 'm' flag) \G End of the previous match \b Word boundary (any position proceeded or followed - but not both - by a letter, digit or underscore) \B Non-word boundary Character and Sets \w Word [a-zA-Z0-9_] \W Non-word [^a-zA-Z0-9_] \d Digit [0-9] \D Non-digit \s Whitespace (Form-feed, tab, vertical-tab, new line, carriage return and space) [\f\t\x0b\n\r ] \S Non-whitespace \x Hexadecimal digit \x00=null; \x0d=\r; [\x61-\x7a]=[a-z] \O Octal digit

. Any character (except new line \n) Groups (...) Capture group - captures a set of characters for a later expression (?:...) Non-capture group - groups an expression but does not capture. e.g. /((?:foo|fu)bar)/ matches "foobar" or "fubar" without "foo" or "fu" appearing as a captured subpattern (? =...) Lookahead - match on the characters following. e.g. /ab(?=c)/ match "ab" only when followed by "c" (?!...) Negative lookahead - match on characters that aren't following. e.g. /ab(?!c)/ match "ab" only when NOT followed by "c" (? <=...) Positive look-behind assertion. e.g. /(?<=foo)bar/ matches "bar" when preceded by "foo" (?

. * \ + |? Additionally the hyphen (-) and close square bracket (]) must be escaped when in an expression set ([...]). e.g. /\(\d{3}\) \d{4}[\- ]\d{4}/ matches "(nnn) nnnn-nnnn" or "(nnn) nnnn nnnn" (where n is a numeric digit). By **doublehelix** cheatography.com/doublehelix/ Published 30th January, 2017. Last updated 31st January, 2017. Page 1 of 1. Sponsored by **Readability-Score.com** Measure your website readability! https://readability-score.com