Temel Regex Desenleri: Kapsamlı Koleksiyon ve Örnekler
Düzenli ifadeler (regex), metin işleme, veri doğrulama ve desen eşleştirme için en güçlü araçlardan biridir. İster kullanıcı girişini doğruluyor, ister metinden belirli bilgileri çıkarıyor veya günlük dosyalarını ayrıştırıyor olun, doğru regex desenine sahip olmak düzinelerce satırlık kodu tek bir ifadeyle değiştirebilir. Bu koleksiyon, hemen kullanabileceğiniz pratik örneklerle birlikte en yaygın ve kullanışlı regex desenlerini sağlar.
Giriş: Temel Regex Desenleri
Her desen, neyle eşleştiğine dair bir açıklama, eşleşen ve eşleşmeyen dizelerin örnekleri ve ne zaman kullanılacağına dair notlar içerir. Bu desenler, çoğu programlama dili (JavaScript, Python, Java, PHP, C#) ve regex motoruyla uyumludur.
| Desen | Açıklama | Eşleşme Örneği |
|---|---|---|
.
| Any single character | a.c matches abc, a1c, a c
|
*
| Zero or more of previous | ab*c matches ac, abc, abbc
|
+
| One or more of previous | ab+c matches abc, abbc
|
?
| Zero or one of previous | colou?r matches color, colour
|
^
| Start of string | ^Hello matches Hello at start
|
$
| End of string | world$ matches world at end
|
[]
| Character class | [aeiou] matches any vowel
|
()
| Capture group | (ab)+ matches ab, abab
|
|
| Alternation (OR) | cat|dog matches cat or dog
|
\d
| Digit [0-9] | \d{3} matches 123
|
\w
| Word character [a-zA-Z0-9_] | \w+ matches hello_123
|
\s
| Whitespace | a\sb matches a b
|
Form Doğrulama Desenleri
Bir e-posta adresi nasıl doğrulanır?
Regex desenlerinizi test etmeye hazır mısınız? Anında eşleşme vurgulama ve ayrıntılı açıklama ile gerçek zamanlı regex testi sunan ücretsiz çevrimiçi regex test aracımızı kullanın.
E-postaları doğrulamak için en yaygın regex deseni şöyledir: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$. Bu, e-posta adresinin temel yapısını kontrol eder: yerel kısım, @ sembolü, alan adı ve en az 2 karakterlik üst seviye alan.
Güçlü bir parola genellikle en az 8 karakter, en az bir büyük harf, bir küçük harf, bir rakam ve bir özel karakter gerektirir. Bunu ileriye bakış iddiaları kullanarak doğrulayabilirsiniz.
Sıkça Sorulan Sorular
Güçlü bir parola regex ile nasıl doğrulanır?
Bir URL'den alan adını çıkarmak için https?://([^/]+) desenini kullanın. Bu, protokolle eşleşir ve ardından bir sonraki eğik çizgiye kadar olan her şeyi yakalar.
Hayır, regex iç içe yapısı nedeniyle HTML'ı ayrıştırmak için uygun değildir. HTML, regex'in yeteneklerini aşan iç içe etiketler içerebilir. Bunun yerine BeautifulSoup (Python), Cheerio (JavaScript) veya Jsoup (Java) gibi uygun bir HTML ayrıştırıcısı kullanın.
\b, eşleşmenin yalnızca bir sözcüğün başında veya sonunda gerçekleşmesini sağlayan bir sözcük sınırıdır. Örneğin, \bcat\b "kedi" ile eşleşir ancak "kedibalığı" ile eşleşmez.
3. Phone Number Validation
Bir URL'den alan adı nasıl çıkarılır?
+ prefix, requires the first digit
to be 1-9 (no leading zeros), and allows up to 15 digits total. This
is the most reliable format for storing and validating phone numbers
internationally.
Matches: +14155552671, 442071838750
Does not match: +01xxxxxxxxx, 123
4. Password Strength
Regex HTML'ı ayrıştırmak için uygun mudur?
(?=.*[...]) syntax uses positive lookaheads to check
for the presence of each character type without consuming
characters.
Matches: MyP@ss1word, Str0ng!Pass
Does not match: password, Password1, P@ss
5. IP Address Validation
Regex'te \b ne anlama gelir?
25[0-5]2[0-4]\d[01]?\d\d?). This is
repeated three times with dots, then once more for the final octet.
Matches: 192.168.1.1, 10.0.0.1, 255.255.255.0
Does not match: 256.1.1.1, 192.168.1, 192.168.1.1.1
6. Date Format Validation
YYYY-MM-DD (ISO 8601)
This pattern validates dates in ISO 8601 format (YYYY-MM-DD). It checks for a four-digit year, a month between 01-12, and a day between 01-31. Note that this pattern validates the format but not the logical validity of the date (for example, it allows 2026-02-31). For complete validation, parse the date and check it programmatically.
Matches: 2026-05-20, 2025-01-01, 2024-12-31
Does not match: 2026-5-20, 2026-13-01, 26-05-20
7. Hex Color Code
CSS Hex Color
#fff#ffffff{1,2} quantifier allows either one or two
repetitions of the 3-hex-digit group, supporting both formats.
Matches: #fff, #FF5733, #1e293b
Does not match: fff, #ff, #1234567
8. Slug / URL-Safe String
URL Slug Pattern
This pattern validates URL slugs: lowercase alphanumeric strings with hyphens as separators. It ensures no leading or trailing hyphens and no consecutive hyphens. This format is SEO-friendly and safe for use in URLs, file names, and identifiers.
Matches: my-blog-post, regex-patterns-guide, tool123
Does not match: My-Post, -slug, slug-, my--post
9. Credit Card Number
General Credit Card Pattern
This pattern validates major credit card numbers: Visa (starts with 4, 13 or 16 digits), Mastercard (starts with 51-55, 16 digits), American Express (starts with 34 or 37, 15 digits), and Discover (starts with 6011 or 65, 16 digits). Combine this with the Luhn algorithm for complete validation.
10. HTML Tag Matching
HTML Tag Extraction
([a-z][a-z0-9]*)\1(.*?) captures the content between
tags using lazy matching to get the shortest match.
Tips for Writing Better Regex
- E-posta: ^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$
- URL: ^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$
- Telefon (ABD): ^\(?([0-9]{3})\)?[-.\s]?([0-9]{3})[-.\s]?([0-9]{4})$
- Posta Kodu (ABD): ^[0-9]{5}(?:-[0-9]{4})?$
- Tarih (YYYY-AA-GG): ^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$
- Saat (SS:DD): ^([01][0-9]|2[0-3]):[0-5][0-9]$
Want to test these regex patterns interactively? Try our free Regex Tester with real-time matching, capture group visualization, and pattern explanations.
Regex Test Aracını DeneFrequently Asked Questions
What is a regex pattern?
A regex (regular expression) pattern is a sequence of characters that defines a search pattern. It is used for string matching, validation, search and replace operations, and text parsing. Regex patterns use special metacharacters like ., *, +, ?, [], (), and {} to define flexible matching rules.
Should I use regex for email validation?
Use regex for basic email format validation (checking for @ symbol, domain structure), but do not try to fully validate email addresses with regex alone. The email specification (RFC 5322) is extremely complex, and no regex can perfectly validate all valid addresses. For production use, combine basic regex validation with actual email verification (sending a confirmation link).
What is the difference between greedy and lazy quantifiers?
Greedy quantifiers (*, +) match as much text as possible, while lazy quantifiers (*?, +?) match as little text as possible. For example, applied to 'aabb', the greedy pattern a.*b matches 'aabb' (the entire string), while the lazy pattern a.*?b matches only 'aab' (the shortest match).
How do I test regex patterns?
Use online regex testers like the ToolHub Regex Tester to interactively test patterns against sample text. These tools highlight matches in real-time, show capture groups, and explain what each part of the pattern does.
Are regex patterns the same across programming languages?
Most regex syntax is shared across languages, but there are differences in advanced features. JavaScript does not support lookbehind assertions in older engines, Python uses different syntax for named groups than JavaScript, and PCRE (PHP) supports more features than most other engines. Always test patterns in your target language.