kirsle.net/www/wiki/Regexp Basics.md

854 B

Regexp Basics

A small reference for some basic things you can do with regular expressions that you can get a lot of mileage out of without getting too in the weeds with crazy features.

Recommended links:

  • Regexr, an interactive regexp explorer.
  • perlretut, where I learned regexp back in the day. It's Perl documentation but the regexp knowledge inside is universally applicable to other programming languages.

This page includes examples and code snippets in various programming languages.

String Search (& Replace)

The simplest regexps deal with just plain old raw text.

// JavaScript
"Hello world".match(/world/);
# Perl
"Hello world" =~ /world/;
# Python
import re
re.match(r'world', "Hello world")