Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

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.

2 REGEX function in MySQL


SQL has REGEX function such as:
REGEXP_LIKE
REGEXP_REPLACE
REGEXP_SUBSTR

Application of REGEX in MySQL 3


Separating email to username, domain name &
domain extension
REGEX
Summary by Group 10

4 Regex Cheatsheet

Literal Character & Shorthands


Metacharater \w
word
example: A-Za-z0-9_
literal piece of text not word
literal character \W
example: a i u e o A I U E O example: , . [space] @ ( +
special character
metacharacter digit
example: $ () * + . ? [] \ ^ { | \d
example: 0-9
not digit
\D
example: + - () a b c A B C
Quantifier & Alteration \s whitespace
1 or more: not whitespace
+ \S
ab+ matches ab, abb, abbb example: a b c 1 2 3
0 or more:
*
ab* matches a, ab, abb
{n} means exactly n:

{}
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

Groups & Assertions


\t tab: \tmomo matches <tab>momo
\n newline/enter: \nmomo matches <enter>momo
\r carriage return
\
metacharacter as literal string
metcacharacter

You might also like