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.
1. Match HTML Tags
Get HTML tags and their corresponding closing tag
<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)
2. Valid Email
\b[\w.!#$%&’*+\/=?^`{|}~-]+@[\w-]+(?:\.[\w-]+)*\b
Username
Minimum 3 characters, max of 16, made of letters, numbers, or dashes
/^[a-z0-9_-]{3,16}$/
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])(?=.*[|!"$%&\/\(\)\?\^\'\\\+\-\*]))^.*
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
Top comments (0)