रेगुलर एक्सप्रेशन टेक्स्ट मिलान के लिए कॉम्पैक्ट पैटर्न हैं, लेकिन इनका सिंटैक्स आसानी से भूल जाता है। यह रेगेक्स चीट शीट उन कैरेक्टर क्लास, एंकर, क्वांटिफ़ायर, ग्रुप, lookaround और फ्लैग को एकत्र करती है जिनका आप सबसे अधिक उपयोग करते हैं, प्रत्येक के संक्षिप्त अर्थ के साथ।
पैटर्न लिखते समय इसे खुला रखें। जब आप किसी पैटर्न को असली टेक्स्ट के विरुद्ध आज़माना चाहें, तो हमारे मुफ्त रेगेक्स टेस्टर का उपयोग करें जो टाइप करते ही लाइव मैच दिखाता है।
Character Classes
| Token | Matches / meaning |
|---|
. | Any character except a newline. |
\d | Any digit (0–9). |
\D | Any non-digit. |
\w | Any word character (letters, digits, underscore). |
\W | Any non-word character. |
\s | Any whitespace (space, tab, newline). |
\S | Any non-whitespace character. |
[abc] | Any one of a, b, or c. |
[^abc] | Any character except a, b, or c. |
[a-z] | Any character in the range a to z. |
Anchors & Boundaries
| Token | Matches / meaning |
|---|
^ | Start of the string (or line with the m flag). |
$ | End of the string (or line with the m flag). |
\b | A word boundary. |
\B | A non-word boundary. |
Quantifiers
| Token | Matches / meaning |
|---|
* | 0 or more of the preceding token. |
+ | 1 or more of the preceding token. |
? | 0 or 1 of the preceding token (optional). |
{n} | Exactly n of the preceding token. |
{n,} | n or more of the preceding token. |
{n,m} | Between n and m of the preceding token. |
*? | Lazy match — as few as possible. |
Groups & Alternation
| Token | Matches / meaning |
|---|
(abc) | Capturing group. |
(?:abc) | Non-capturing group. |
(?<name>abc) | Named capturing group. |
a|b | Match a or b (alternation). |
\1 | Backreference to the first capturing group. |
Lookaround
| Token | Matches / meaning |
|---|
(?=abc) | Positive lookahead — followed by abc. |
(?!abc) | Negative lookahead — not followed by abc. |
(?<=abc) | Positive lookbehind — preceded by abc. |
(?<!abc) | Negative lookbehind — not preceded by abc. |
Flags
| Token | Matches / meaning |
|---|
g | Global — find all matches, not just the first. |
i | Case-insensitive matching. |
m | Multiline — ^ and $ match line starts/ends. |
s | Dotall — . also matches newlines. |
u | Unicode mode. |
y | Sticky — match from lastIndex only. |
रेगेक्स चीट शीट से जुड़े सामान्य प्रश्न
मैं रेगुलर एक्सप्रेशन कहां टेस्ट कर सकता हूं?
हमारा मुफ्त
रेगेक्स टेस्टर आज़माएं, जो आपके टेक्स्ट में हर मैच को रियल-टाइम में हाइलाइट करता है और सभी JavaScript फ्लैग का समर्थन करता है।
greedy और lazy क्वांटिफ़ायर में क्या अंतर है?
* और + जैसे greedy क्वांटिफ़ायर जितना संभव हो उतना मैच करते हैं। एक ? जोड़ने पर (उदाहरण *?) वे lazy बन जाते हैं, जितना कम संभव हो उतना मैच करते हैं।
regex में \b का क्या मतलब है?
\b एक word boundary है — किसी word कैरेक्टर और non-word कैरेक्टर के बीच शून्य-चौड़ाई की स्थिति। यह पूरे शब्द मिलाने के लिए उपयोगी है, जैसे \bcat\b।
capturing और non-capturing ग्रुप में क्या अंतर है?
एक capturing ग्रुप (abc) अपने मैच को बाद में उपयोग या backreference के लिए संग्रहीत करता है। एक non-capturing ग्रुप (?:abc) बिना संग्रहीत किए समूहित करता है, जो तब थोड़ा तेज़ होता है जब आपको captured मान की आवश्यकता नहीं होती।
क्या यह regex सिंटैक्स JavaScript में काम करता है?
हां। यह चीट शीट JavaScript (ECMAScript) रेगुलर एक्सप्रेशन सिंटैक्स का पालन करती है, और वही टोकन अधिकांश आधुनिक भाषाओं में भी काम करते हैं।