Sign in Start free

Regex pattern library

Tested regular expressions you can open in the tester, read the explanation of and adapt. Each pattern comes with sample text and unit tests. Save your own pattern with Save & share and tick “publish” to add it here.

52 patterns

★Thai mobile phone number

(?:\+66[ -]?|0)([689]\d)[ -]?(\d{3})[ -]?(\d{4})\b

Mobile numbers 06x, 08x, 09x with optional dashes or spaces, or the +66 international form.

Thai JavaScript /g 3 views ▲ 0

★CSS hex color

#((?:[\da-fA-F]{3}){1,2}|(?:[\da-fA-F]{4}){1,2})\b

#RGB, #RGBA, #RRGGBB and #RRGGBBAA colors. Group 1 holds the hex digits.

Web & URLs JavaScript /g 1 views ▲ 0

★IPv4 address

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

Matches dotted IPv4 addresses with every octet between 0 and 255 – 256.1.1.1 or 1.2.3 do not match.

Web & URLs JavaScript /g 1 views ▲ 0

★Apache / Nginx access log

^(?<ip>\S+) \S+ \S+ \[(?<time>[^\]]+)\] "(?<method>[A-Z]+) (?<path>\S+) [^"]*" (?<status>\d{3}) (?<size>\d+|-)(?: "(?<referrer>[^"]*)" "(?<agent>[^"]*)")?

Parses the combined log format into named groups: ip, time, method, path, status, size, referrer and agent.

Logs & Ops JavaScript /gm 0 views ▲ 0

★Leading and trailing whitespace

^[ \t]+|[ \t]+$

Selects spaces and tabs at the start or end of every line – replace with nothing to trim.

Text Cleanup JavaScript /gm 0 views ▲ 0

★Strong password

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[^\w\s]).{8,}$

At least 8 characters with a lowercase letter, an uppercase letter, a digit and a special character – each rule is one lookahead, so they are easy to change.

Validation JavaScript /gm 0 views ▲ 0

★ISO date YYYY-MM-DD

\b(?<year>\d{4})-(?<month>0[1-9]|1[0-2])-(?<day>0[1-9]|[12]\d|3[01])\b

Dates in ISO 8601 format with month 01–12 and day 01–31, with named groups year, month and day. Does not check days per month.

Dates & Times JavaScript /g 0 views ▲ 0

★URL (http / https)

https?:\/\/(?:www\.)?[-\w@:%.+~#=]{1,256}\.[a-zA-Z\d()]{1,6}\b(?:[-\w()@:%+.~#?&/=]*[\w/])?

Finds web addresses starting with http:// or https:// including port, path, query string and fragment. Stops before trailing punctuation like a closing parenthesis or full stop.

Web & URLs JavaScript /g 0 views ▲ 0

★E-mail address (practical)

^[\w.+-]+@[A-Za-z\d-]+(\.[A-Za-z\d-]+)*\.[A-Za-z]{2,}$

Accepts the e-mail addresses people really use (letters, digits, dots, plus tags, hyphens, multi-level domains) and rejects common typos. Anchored for validating a whole input value.

Validation JavaScript /gm 0 views ▲ 0

Markdown links

(?<!!)\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)

[text](url "title") links: group 1 text, group 2 URL, group 3 optional title. Images (![…]) are skipped.

Other JavaScript /g 1 views ▲ 0

File name and extension

^(.+?)(?:\.([^.\\/]+))?$

Splits a file name into base name (group 1) and extension (group 2). Handles names with several dots.

Other JavaScript /gm 1 views ▲ 0

Thai national ID number (format)

\b\d(?:-?\d{4})(?:-?\d{5})(?:-?\d{2})-?\d\b

13 digits, plain or written as 1-2345-67890-12-3. Check the last digit (checksum) in code.

Thai JavaScript /g 1 views ▲ 0

Java stack trace frames

^\s+at ([\w$.]+)\.([\w$<>]+)\(([^:)]+)(?::(\d+))?\)

Each "at package.Class.method(File.java:123)" line with class, method, file and line number in groups.

Logs & Ops JavaScript /gm 1 views ▲ 0

Log level and message

^(?<ts>\d{4}-\d{2}-\d{2}[ T]\d{2}:\d{2}:\d{2}(?:[.,]\d+)?)\s+(?<level>TRACE|DEBUG|INFO|WARN(?:ING)?|ERROR|FATAL)\s+(?<msg>.*)$

Timestamp, level and message of typical application log lines (Spring Boot, Log4j, Python logging).

Logs & Ops JavaScript /gm 1 views ▲ 0

Sentences

[A-Z][^.!?]*[.!?]

A sentence starts with an uppercase letter and ends with . ! or ?.

Text Cleanup JavaScript /g 1 views ▲ 0

Windows file path

\b[A-Za-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*([^\\/:*?"<>|\r\n]*)

Drive-letter paths like C:\Users\name\file.txt; group 1 is the file name.

Other JavaScript /g 0 views ▲ 0

Amounts in baht

(?:฿\s?)?\d{1,3}(?:,\d{3})*(?:\.\d{2})?\s?(?:บาท|THB)|฿\s?\d{1,3}(?:,\d{3})*(?:\.\d{2})?

Numbers followed by บาท, ฿ or THB, with optional thousands separators and satang.

Thai JavaScript /gu 0 views ▲ 0

Thai text runs

[\p{Script=Thai}]+

Runs of Thai characters (needs the u flag) – useful to separate Thai from English in mixed text.

Thai JavaScript /gu 0 views ▲ 0

Thai postal code

\b(?:[1-8]\d|9[0-6])\d{3}\b

Five-digit postal codes from 10000 to 96xxx.

Thai JavaScript /g 0 views ▲ 0

MAC address

\b[\da-fA-F]{2}([:-])(?:[\da-fA-F]{2}\1){4}[\da-fA-F]{2}\b

Six pairs of hex digits separated by colons or hyphens (the same separator throughout).

Logs & Ops JavaScript /g 0 views ▲ 0

Hashtags and @mentions

(?<![\w@#])([#@])([\p{L}\p{N}_]+)

#hashtags and @mentions, Unicode letters included (u flag). Group 1 is the symbol, group 2 the name.

Text Cleanup JavaScript /gu 0 views ▲ 0

Words (any language)

[\p{L}\p{M}]+(?:['’-][\p{L}\p{M}]+)*

Unicode letters and marks with the u flag – also matches Thai, accented and other scripts.

Text Cleanup JavaScript /gu 0 views ▲ 0

Blank lines

^\s*$\n?

Matches empty lines and lines with only whitespace – replace with nothing to remove them.

Text Cleanup JavaScript /gm 0 views ▲ 0

Duplicate words

\b(\w+)\s+\1\b

Finds a word repeated twice in a row ("the the"), ignoring case. Group 1 is the word.

Text Cleanup JavaScript /gi 0 views ▲ 0