DEV Community

caelinsutch
caelinsutch

Posted on

1 1

My EZ Regex Cookbook

What is Regex?

Regex is short for a "Regular Expression", which is a sequence of characters that define a search pattern for text. Usually, these are used to perform search or replace operations on strings, or for input validation. You can use Regex in practically every language to perform operations on strings.

Regex can be confusing as hell to write, but here are some of the most common Regex expressions for you to use in your software.

Pattern

1. Match HTML Tags

Get HTML tags and their corresponding closing tag

<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)

Pattern

2. Valid Email

\b[\w.!#$%&’*+\/=?^`{|}~-]+@[\w-]+(?:\.[\w-]+)*\b

Pattern
Pattern

Username

Minimum 3 characters, max of 16, made of letters, numbers, or dashes

/^[a-z0-9_-]{3,16}$/

Pattern
Pattern

Strong Password

Minimum of 6 characters, at least one uppercase letter, one lowercase letter, a number, and a special character

(?=^.{6,}$)((?=.*\w)(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[|!"$%&\/\(\)\?\^\'\\\+\-\*]))^.*

Pattern

IPv4 Address

Matches any valid IPv4 address inside text

\b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b

Speedy emails, satisfied customers

Postmark Image

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay