เข้าสู่ระบบ เริ่มใช้ฟรี

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.

ภาษาไทย JavaScript /g 3 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.

Log และงานระบบ JavaScript /gm 2 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.

จัดการข้อความ JavaScript /gm 2 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.

ตรวจสอบข้อมูล JavaScript /gm 2 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.

วันที่และเวลา JavaScript /g 2 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.

เว็บและ URL JavaScript /g 2 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.

เว็บและ URL JavaScript /g 2 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.

เว็บและ URL JavaScript /g 2 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.

ตรวจสอบข้อมูล JavaScript /gm 2 views ▲ 0

Markdown links

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

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

อื่น ๆ JavaScript /g 2 views ▲ 0

File name and extension

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

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

อื่น ๆ JavaScript /gm 2 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.

อื่น ๆ JavaScript /g 2 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.

ภาษาไทย JavaScript /gu 2 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.

ภาษาไทย JavaScript /gu 2 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.

ภาษาไทย JavaScript /g 2 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).

Log และงานระบบ JavaScript /g 2 views ▲ 0

Sentences

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

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

จัดการข้อความ JavaScript /g 2 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.

จัดการข้อความ JavaScript /gu 2 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.

จัดการข้อความ JavaScript /gi 2 views ▲ 0

Thai postal code

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

Five-digit postal codes from 10000 to 96xxx.

ภาษาไทย 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.

Log และงานระบบ 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).

Log และงานระบบ JavaScript /gm 1 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.

จัดการข้อความ JavaScript /gu 1 views ▲ 0

Blank lines

^\s*$\n?

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

จัดการข้อความ JavaScript /gm 1 views ▲ 0