Referensi ekspresi reguler lengkap dengan sintaks, flag, grup, lookahead, dan contoh pola dunia nyata.
Coba di Tester Regex โ| Sintaks | Deskripsi |
|---|---|
. | Any character except newline |
\d | Digit [0-9] |
\D | Non-digit [^0-9] |
\w | Word char [a-zA-Z0-9_] |
\W | Non-word character |
\s | Whitespace (space, tab, newline) |
\S | Non-whitespace |
[abc] | One of a, b, or c |
[^abc] | Not a, b, or c |
[a-z] | Character in range aโz |
[a-zA-Z] | Letter (any case) |
\p{L} | Any Unicode letter (u flag) |
| Sintaks | Deskripsi |
|---|---|
^ | Start of string (or line with m flag) |
$ | End of string (or line with m flag) |
\b | Word boundary |
\B | Non-word boundary |
\A | Start of string (Python/Java) |
\Z | End of string (Python/Java) |
| Sintaks | Deskripsi |
|---|---|
* | 0 or more (greedy) |
+ | 1 or more (greedy) |
? | 0 or 1 (optional) |
{n} | Exactly n times |
{n,} | n or more times |
{n,m} | Between n and m times |
*? | 0 or more (lazy) |
+? | 1 or more (lazy) |
?? | 0 or 1 (lazy) |
| Sintaks | Deskripsi |
|---|---|
(abc) | Capturing group |
(?:abc) | Non-capturing group |
(?<name>abc) | Named capturing group |
\1 | Backreference to group 1 |
\k<name> | Named backreference |
(?|...) | Branch reset group (PCRE) |
| Sintaks | Deskripsi |
|---|---|
(?=abc) | Positive lookahead โ must be followed by abc |
(?!abc) | Negative lookahead โ must NOT be followed by abc |
(?<=abc) | Positive lookbehind โ must be preceded by abc |
(?<!abc) | Negative lookbehind โ must NOT be preceded by abc |
| Flag | Nama | Deskripsi |
|---|---|---|
g | Global | Find all matches, not just the first |
i | Case-insensitive | Match regardless of case (A = a) |
m | Multiline | ^ and $ match start/end of each line |
s | Dotall | . matches newline characters too |
u | Unicode | Enable full Unicode support (\p{} classes) |
y | Sticky | Match only at lastIndex position (JS) |
x | Extended | Allow whitespace + comments in pattern (Python/PHP) |
| Pola | Regex | Uji |
|---|---|---|
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,} | Coba di Tester Regex โ | |
| URL | https?:\/\/[\w\-]+(\.[\w\-]+)+[\w\-._~:/?#[\]@!$&'()*+,;=%]* | Coba di Tester Regex โ |
| IPv4 Address | \b(?:(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\.){3}(?:25[0-5]|2[0-4]\d|[01]?\d\d?)\b | Coba di Tester Regex โ |
| Phone (US) | \+?1?[\s.-]?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4} | Coba di Tester Regex โ |
| Date (YYYY-MM-DD) | \d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01]) | Coba di Tester Regex โ |
| Time (HH:MM) | (?:[01]\d|2[0-3]):[0-5]\d | Coba di Tester Regex โ |
| UUID | [0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12} | Coba di Tester Regex โ |
| Hex Color | #(?:[0-9a-fA-F]{3}){1,2}\b | Coba di Tester Regex โ |
| Slug | [a-z0-9]+(?:-[a-z0-9]+)* | Coba di Tester Regex โ |
| ZIP Code (US) | \d{5}(?:-\d{4})? | Coba di Tester Regex โ |
| Credit Card | (?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}) | Coba di Tester Regex โ |
| HTML Tag | <([a-zA-Z][a-zA-Z0-9]*)(?:\s[^>]*)?\/?>.*?<\/\1> | Coba di Tester Regex โ |
| Markdown Bold | \*\*([^*]+)\*\* | Coba di Tester Regex โ |
| JWT Token | [A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+ | Coba di Tester Regex โ |
| Semver | \bv?(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[\w.]+)?\b | Coba di Tester Regex โ |
| GitHub Username | (?<=github\.com\/)([a-zA-Z0-9](?:[a-zA-Z0-9-]{0,37}[a-zA-Z0-9])?) | Coba di Tester Regex โ |
| Positive Integer | ^[1-9]\d*$ | Coba di Tester Regex โ |
| Float / Decimal | -?\d+(?:\.\d+)? | Coba di Tester Regex โ |
| Blank Lines | ^\s*$ | Coba di Tester Regex โ |
| Duplicate Words | \b(\w+)\s+\1\b | Coba di Tester Regex โ |
Ekspresi reguler adalah urutan karakter yang mendefinisikan pola pencarian. Digunakan untuk pencarian string, pencocokan, dan manipulasi. Regex didukung secara native di JavaScript, Python, Java, PHP, Go, dan sebagian besar bahasa pemrograman modern.
Kuantifier rakus (*, +, {n,m}) cocok dengan sebanyak mungkin karakter. Kuantifier malas (*?, +?, {n,m}?) cocok dengan sesedikit mungkin karakter.
Lookahead (?=...) dan lookbehind (?<=...) adalah pernyataan lebar nol โ mereka memeriksa pola tanpa mengonsumsi karakter. Lookahead positif (?=foo) menegaskan bahwa 'foo' mengikuti. Lookahead negatif (?!foo) menegaskan bahwa 'foo' TIDAK mengikuti.
Sintaks inti (kelas karakter, kuantifier, jangkar) konsisten di sebagian besar bahasa. Namun, fitur seperti lookbehind, grup bernama, dan flag spesifik bervariasi menurut mesin.