Professional Documents
Culture Documents
Regex
Regex
Summary by Group 10
What is REGEX? 1
A regular expression (regex) is a
character sequence used to
detect a pattern within a text.
Regex may be found in a variety of
applications and computer
languages, including MySQL.
4 Regex Cheatsheet
{}
a{2} matches aa, aab
{m,n} means between m and n: Groups & Assertions
a{2,4} matches aa, aaa, aaaa
group:
0 or 1: ()
? (ha)+ matches ha, haha, hahaha
ab? matches a, ab
group:
or: (|)
| (ju)+ or (av)+ matches juice, avocado, justice av
ab|cd matches ab, cd
non-capturing group:
?: (?:on) matches but not capturing python, hackathon,
moron
Anchor ?=
positive lookahead:
s(?=cream) matches scream but not stream
start of the string: positive lookbehind:
^ ?<=
^boy matches boy eats donut. (?<=iron)man matches ironman but not superman
end of the string: negative lookahead:
$
fish$ matches she sells fish ?!
s(?!cream) matches stream but not scream
boundary:
\b negative lookbehind:
s\b matches mas, mass, masses ?<!
(?<!iron)man matches superman but not ironman