Regular Expressions

August 21, 2017
regex

Note: If you find any issues in the post, do let me know in the comments section.

Regular Expressions

Character classes

dot class

match Any

word

not word

digit

not digit

space

not space

character set

example

expression: [aeiou]

phrase: glib jocks vex dwarves!

result: glib jocks vex dwarves!

negated character set

example

expression: [aeiou]

phrase: glib jocks vex dwarves!

result: glib jocks vex dwarves!

range character set

example

expression: [g-i]

phrase: abcdefghijklmnopqrstuvwxyz

result: abcdefghijklmnopqrstuvwxyz

Anchor tags

beginning

ending

Groups

capturing group

non-capturing group

Quantifiers & Alternations

plus

example

expression: Fo+

phrase: abcdefghijklmnopqrstuvwxyz

result: abcdefghijklmnopqrstuvwxyz

star

example

expression: Fo*

matches

Fo
Foo
Fooooo
Foooooooo

alternation

example

expression: b(a|e|u)d

phrase: bad bud bod bed bid

matches: bad bud bod bed bid

optional

example

expression: colou?r

phrase: color colour

matches: color colour

quantifiers

example

expression: be{2,4}

phrase: be beeee beeeee

matches: be beeee beeeee

comments powered by Disqus