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
(?:\+66[ -]?|0)([689]\d)[ -]?(\d{3})[ -]?(\d{4})\b
Mobile numbers 06x, 08x, 09x with optional dashes or spaces, or the +66 international form.
#((?:[\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.
\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.
^(?<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.
^[ \t]+|[ \t]+$
Selects spaces and tabs at the start or end of every line – replace with nothing to trim.
^(?=.*[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.
\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.
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.
^[\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.
(?<!!)\[([^\]]+)\]\(([^)\s]+)(?:\s+"([^"]*)")?\)
[text](url "title") links: group 1 text, group 2 URL, group 3 optional title. Images (![…]) are skipped.
^(.+?)(?:\.([^.\\/]+))?$
Splits a file name into base name (group 1) and extension (group 2). Handles names with several dots.
\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.
^\s+at ([\w$.]+)\.([\w$<>]+)\(([^:)]+)(?::(\d+))?\)
Each "at package.Class.method(File.java:123)" line with class, method, file and line number in groups.
^(?<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).
[A-Z][^.!?]*[.!?]
A sentence starts with an uppercase letter and ends with . ! or ?.
\b[A-Za-z]:\\(?:[^\\/:*?"<>|\r\n]+\\)*([^\\/:*?"<>|\r\n]*)
Drive-letter paths like C:\Users\name\file.txt; group 1 is the file name.
(?:฿\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.
[\p{Script=Thai}]+
Runs of Thai characters (needs the u flag) – useful to separate Thai from English in mixed text.
\b(?:[1-8]\d|9[0-6])\d{3}\b
Five-digit postal codes from 10000 to 96xxx.
\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).
(?<![\w@#])([#@])([\p{L}\p{N}_]+)
#hashtags and @mentions, Unicode letters included (u flag). Group 1 is the symbol, group 2 the name.
[\p{L}\p{M}]+(?:['’-][\p{L}\p{M}]+)*
Unicode letters and marks with the u flag – also matches Thai, accented and other scripts.
^\s*$\n?
Matches empty lines and lines with only whitespace – replace with nothing to remove them.
\b(\w+)\s+\1\b
Finds a word repeated twice in a row ("the the"), ignoring case. Group 1 is the word.