Skip to content

Instantly share code, notes, and snippets.

View stevecalla's full-sized avatar

Steve Calla (he/him) stevecalla

  • Boulder, Colorado
  • 08:31 (UTC -06:00)
View GitHub Profile

REGEX TUTORIAL

REGEX is short for regular expression. A regular expression is way to search for a sequence of characters or a character pattern in a body of text. REGEX uses a search pattern that can be difficult to understand but can find multiple instances of a character pattern throughout a text document.

For example, if I want to find a phone number in a body of text (such as a markdown document or javascript code or simply an article or word document), I can use a REGEX search pattern.

The following REGEX search pattern will find all phone numbers (e.g. 123-456-7899) that match this pattern of 3 digits followed by a "-" followed by 3 digits followed by a "-" followed by 4 digits. The REGEX to do so is

REGEX = "\d{3}-\d{3}-\d{4f}"
// Port, host and auth token of Redis server might be defined as environment
// variables. If not, fall back to defaults.
var redisPort = process.env.REDIS_PORT || 6379,
redisHost = process.env.REDIS_HOST || '127.0.0.1',
redisAuth = process.env.REDIS_AUTH || null,
redis = require('redis');
// Since we are waiting for the error event, we don't have to check for errors
// individually after each Redis command.
var onError = function (error) {
<img width="1062" alt="Screenshot 2024-08-12 at 12 05 42 PM" src="https://gist.github.com/user-attachments/assets/4010cc94-9dc4-4f57-8160-80a1c284c62b">