Member-only story

Regex Tutorial — A Quick Cheatsheet by Examples

Naveen Metta
4 min readFeb 9, 2025

--

credit goes to the owner : https://greygiant.com/2023/03/26/regex/
source: greygiant.com

Regular expressions (regex) are like special search patterns that help you find and work with text. Think of them as a super-powered way to search through text, kind of like the “Find” feature in your text editor, but much more powerful. In this guide, we’ll learn regex through simple examples that you can try right away.

What is Regex?

Regex is a set of characters that create a search pattern. It’s used in:

  • Finding text patterns
  • Replacing text
  • Validating text (like checking if an email address is written correctly)
  • Extracting information from text

Basic Patterns

1. Simple Text Matching

The most basic way to use regex is to find exact text:

pattern = "hello"
# This will find the word "hello" in text

For example, this will match:

  • “hello world”
  • “say hello to everyone”
  • “hello123”

2. Special Characters

Some characters have special meanings in regex:

  • . (dot) - matches any single character except newline

--

--

Naveen Metta
Naveen Metta

Written by Naveen Metta

I'm a Full Stack Developer with 3+ years of experience. feel free to reach out for any help : mettanaveen701@gmail.com

No responses yet