Member-only story
Primer on Regular Expressions
In this post, I will try to give you a practical overview of Regular Expressions to teach you what they are, what they can be used for and a quick intro to how you can use them.
What are Regular Expressions even?
Regular Expressions (short Regexes) are Strings that work as a DSL (domain-specific language) to do some common tasks within other Strings. A DSL can also be subscribed as “a programming language within a programming language”.
In the case of Regexes, the outer programming language can be any programming language that supports the String
type, it just has to support Regexes. Nearly all popular programming languages support Regexes, which makes Regexes so useful to know. The inner language of Regexes consists of only String
with some characters having a special meaning.
For example in the String ".*@.*\\.com"
the .
means "any character", the *
means "any amount of <whatever precedes>", together .*
means "any amount of any character". Then we have a non-special character @
, then again .*
followed by \\
which means "escape the next character and treat like a non-special character" so \\.
together reads like a normal .
character without the special meaning "any character"…