Regex tutorial — A quick cheatsheet by examples

Jonny Fox
Factory Mind
Published in
6 min readJun 23, 2017

--

UPDATE 03/2024: See further explanations/answers in story responses!

Check out my REGEX COOKBOOK article about the most commonly used (and most wanted) regex 🎉

Regular expressions (regex or regexp) are extremely useful in extracting information from any text by searching for one or more matches of a specific search pattern (i.e. a specific sequence of ASCII or unicode characters).

Fields of application range from validation to parsing/replacing strings, passing through translating data to other formats and web scraping.

One of the most interesting features is that once you’ve learned the syntax, you can actually use this tool in (almost) all programming languages ​​(JavaScript, Java, VB, C #, C / C++, Python, Perl, Ruby, Delphi, R, Tcl, and many others) with the slightest distinctions about the support of the most advanced features and syntax versions supported by the engines.

Let’s start by looking at some examples and explanations.

Basic topics

Anchors — ^ and $

^The        matches any string that starts with The -> Try it!end$        matches a string that ends with end^The end$   exact string match (starts and…

--

--