Skip to content
Regex चीटशीट
Tools

Regex चीटशीट

नया

regular expression टोकन और flags का खोजने योग्य संदर्भ।

Live regex tester

Type a pattern and a test string — matches highlight instantly, with every capture group broken out below.

/ /
Flags
Matches
Capture groups

Common regex patterns

Battle-tested patterns — load one into the tester to see it run, or copy it straight out.

Email address
[\w.+-]+@[\w-]+\.[\w.-]+
URL (http/https)
https?:\/\/[^\s]+
US phone number
\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}
Date (YYYY-MM-DD)
(\d{4})-(\d{2})-(\d{2})
Time (24-hour)
([01]?\d|2[0-3]):[0-5]\d
IPv4 address
\b(?:\d{1,3}\.){3}\d{1,3}\b
Hex color
#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{3})\b
Slug / username
[a-z0-9]+(?:-[a-z0-9]+)*
Whole number / integer
-?\d+
Strong password (8+, mixed)
(?=.*[a-z])(?=.*[A-Z])(?=.*\d).{8,}
Duplicate word
\b(\w+)\s+\1\b
Trailing whitespace
[ \t]+$

Regex cheat sheet

Every token, grouped with a quick example. Search by symbol or keyword; click any token to copy it.

Regex flavors: JavaScript, Python, Java, PCRE & grep

The tester above runs JavaScript regex. Most syntax is shared — here's what differs between engines.

FeatureJavaScriptPython (re)JavaPCRE / grep
Named group(?<name>…)(?P<name>…)(?<name>…)(?P<name>…)
Dotall (. matches \n)s flagre.DOTALL / (?s)Pattern.DOTALL(?s)
Ignore casei flagre.IGNORECASE / (?i)(?i) flag(?i) / grep -i
Lookbehind(?<=…) ES2018+SupportedSupportedgrep -P only
Backslash in source/\d/ literalr"\d" raw string"\\d" doubled\d
Find every matchstr.matchAll(/…/g)re.findall()Matcher.find()grep -o
POSIX class [[:digit:]]use \d insteaduse \d insteadsupportedsupported

Runs entirely in your browser. Nothing is uploaded.

Regex cheat sheet उदाहरण सहित — और live tester भी

यह regex cheat sheet हर regular expression token को एक जगह रखता है — और साथ में एक live tester भी देता है ताकि आप pattern देखते ही उसे try कर सकें। Pattern type करें, flags चुनें, test string paste करें, और matches तुरंत highlight हो जाते हैं जबकि हर capture group नीचे दिखाई देता है।

कुछ भी install नहीं करना और कोई account नहीं बनाना: पूरा regular expression reference आपके browser में चलता है, इसलिए जो text आप test करते हैं वो कभी upload नहीं होता। No ads, no login wall, test strings पर कोई size limit नहीं।

हर regex token, उदाहरणों के साथ

Reference में वो syntax शामिल है जो आप असल में use करते हैं: character classes (\d, \w, \s और custom sets जैसे [a-z]), anchors और boundaries (^, $, \b), quantifiers (*, +, ?, {n,m} और उनके lazy forms), groups और alternation, lookahead और lookbehind, flags g i m s u y, और literal dots व slashes के लिए जरूरी escapes।

हर entry के साथ एक छोटा, concrete example है — \bcat\b 'cat' शब्द को match करता है लेकिन 'category' को नहीं — ताकि मतलब याद रहे। regex tokens को symbol या keyword से search करें और किसी भी एक को click करके copy करें।

Pattern बनाते समय तुरंत test करें

Static cheat sheets ये नहीं बता सकते कि आपका pattern वाकई काम करता है या नहीं। Built-in regex tester आपकी expression को live compile करता है, sample text में हर match highlight करता है, और हर match के numbered और named capture groups की list बनाता है।

Global, case-insensitive, multiline, dotall, Unicode और sticky flags toggle करें और results को बदलते देखें। अगर pattern invalid है तो silent failure की जगह plain Hindi में error मिलती है — और pattern को real time में match होते देखना regex सीखने का सबसे तेज तरीका है।

Common regex patterns, copy करने के लिए तैयार

कुछ patterns बार-बार काम आते हैं — email addresses, URLs, phone numbers, ISO dates, IPv4 addresses, hex colors और strong password checks। Common patterns section आपको इनका एक tested version देता है: इसे सीधे tester में load करें ताकि example text पर चलते देख सकें, या अपने code में copy करें।

ये pragmatic starting points हैं जिन्हें आप अपने हिसाब से adapt कर सकते हैं — one-size-fits-all rules नहीं — इसीलिए इन्हें अपने असल data पर test करना जरूरी है।

यह regex101.com और regexr.com से कैसे अलग है

regex101.com web पर सबसे popular dedicated regex tool है — और सही कारण से। यह छह regex flavors (PCRE, Python re, Golang, Java, .NET, और JavaScript) को support करता है, token-by-token explanation panel दिखाता है, और match history track करता है। अगर आप किसी complex production pattern को debug कर रहे हैं या verify करना चाहते हैं कि pattern PHP और Python में एक जैसा behave करे, तो regex101 सही tool है। regexr.com भी इसी तरह का experience देता है साथ में contributed patterns की public community library के साथ।

यह UtiloKit page workflow में एक अलग जगह पर है। यह एक searchable token reference table को live tester के साथ एक ही screen पर combine करता है, उस common situation के लिए optimize किया गया है जहाँ आपको roughly पता है क्या चाहिए लेकिन exact syntax याद नहीं। आप आते हैं, token lookup करते हैं, एक quick test string paste करते हैं, और editor पर वापस जाते हैं — no tab-switching, no account, no ads। Developers के लिए जो दिन में दर्जनों बार regex101.com पर सिर्फ यह याद करने जाते हैं कि lookbehind (?<=…) use करता है या (?<!…), एक dedicated searchable reference measurably तेज है। दोनों use करें: regex101 deep debugging के लिए, यह page quick lookups के लिए।

Regex flavors: JavaScript, Python, Java, PCRE और grep

ज्यादातर regex syntax portable है, लेकिन engines details में अलग होते हैं। यहाँ का tester JavaScript regex use करता है, वही flavor जो Node.js और browser में है। Python का re module raw strings जैसे r"\d+" चाहता है और groups को (?P<name>…) से name करता है; Java को string literals में doubled backslashes चाहिए; PCRE (PHP, और grep -P) सबसे feature-complete है; और POSIX grep -E की अपनी escaping quirks हैं।

Flavor table named groups, dotall, case-insensitivity, lookbehind और 'find all' को हर engine में call out करता है, ताकि आप एक python regex cheat sheet pattern को JavaScript में — या उल्टे — बिना किसी surprise के move कर सकें।

Greedy vs lazy, और दूसरे common mistakes

दो चीजें लगभग सबको परेशान करती हैं। पहली, quantifiers greedy होते हैं: .+ जितना हो सके उतना grab करता है, इसलिए एक single HTML tag match करने के लिए आप usually lazy .+? चाहते हैं। दूसरी, metacharacters को escape करना भूल जाना — एक bare . कोई भी character match करता है, जबकि \. एक literal dot match करता है, इसलिए price regex के लिए \d+\.\d{2} चाहिए।

Cheat sheet को काम करते समय खुला रखें और ये surprises नहीं रहते।

Private, instant और free

कुछ भी install नहीं करना और कोई account नहीं बनाना। हर lookup, हर match और हर copy आपके browser में locally होती है — आपके patterns और test data कभी आपके device से बाहर नहीं जाते। इस regex cheat sheet को bookmark करें और जब भी कोई token याद न आए या pattern को sanity-check करना हो, इसे open करें।

Frequently asked questions

Regular expression क्या होता है उदाहरण सहित?

Regular expression (regex) एक compact pattern है जो strings के एक set को describe करता है, text को search, match और replace करने के लिए use होता है। उदाहरण के लिए, pattern \d{3}-\d{4} एक phone fragment जैसे 555-1234 को match करता है, क्योंकि \d का मतलब 'एक digit' है और {3} का मतलब 'exactly तीन'। Regex लगभग हर programming language और code editor में find-and-replace, form validation और log parsing को power करता है। इस page के top पर live tester आपको कोई भी pattern instantly try करने देता है।

Basic regex tokens कौन से होते हैं?

Building blocks हैं: . (newline को छोड़कर कोई भी character), \d (एक digit), \w (एक word character — letter, digit या underscore), \s (whitespace), anchors ^ (start) और $ (end), और quantifiers * (zero or more), + (one or more) और ? (optional)। तो \w+ एक पूरा word match करता है और \d+ एक पूरा number जैसे 2024। इन्हें combine करें — ^\d+$ एक ऐसी line match करता है जिसमें सिर्फ digits हों। इस cheat sheet पर हर token के साथ एक copyable example है।

\d, \w और \s का क्या मतलब होता है?

\d कोई भी digit 0–9 match करता है; \w एक word character (a–z, A–Z, 0–9 या _) match करता है; \s whitespace (space, tab या newline) match करता है। इनके uppercase versions negations हैं: \D non-digit है, \W non-word character है और \S non-space। उदाहरण के लिए, text 'a5 b' में, \d matches 5, \w matches a, 5 और b, और \s उनके बीच के space को match करता है। ये तीन shorthand classes रोजमर्रा के regex patterns के vast majority को cover करती हैं।

Regex anchors क्या होते हैं?

Anchors एक character की जगह एक position match करते हैं। ^ string का start match करता है (या m flag के साथ हर line का), $ end match करता है, \b एक word boundary match करता है और \B non-boundary match करता है। उदाहरण के लिए, ^\d+$ एक ऐसी string match करता है जो सिर्फ digits से बनी हो, और \bcat\b 'cat' शब्द को match करता है लेकिन 'category' के अंदर के 'cat' को नहीं। Anchors को अक्सर character matchers समझ लिया जाता है — ये text में characters नहीं, positions match करते हैं।

Regex में quantifiers क्या होते हैं?

Quantifiers बताते हैं कि पिछला token कितनी बार repeat हो सकता है: * zero or more है, + one or more है, ? zero or one (optional) है, {n} exactly n है, {n,} n or more है, और {n,m} n और m के बीच है। ये default में greedy होते हैं (जितना हो सके उतना match करते हैं); lazy बनाने के लिए ? add करें। उदाहरण के लिए \d{1,3} 1 से 3 digits match करता है, और lazy .+? जितना हो सके उतना कम match करता है। Lazy quantifiers HTML tags या quoted strings match करते समय essential होते हैं।

Groups और capture groups क्या होते हैं?

Parentheses (…) एक capturing group बनाते हैं जिसे आप extract या reuse कर सकते हैं — (\d{4})-(\d{2}) '2024-06' में group 1 में year और group 2 में month capture करता है। जब आपको सिर्फ quantifier के लिए group करना हो तो (?:…) non-capturing group use करें, और (?<name>…) जैसे (?<year>\d{4}) named group के लिए। \1 जैसा backreference group 1 ने जो capture किया उसे फिर से match करता है, तो (\w)\1 एक doubled letter find करता है — 'hello' में 'll'।

Lookahead और lookbehind क्या होते हैं?

Lookarounds assert करते हैं कि text आपके match के बगल में है (या नहीं) बिना उसे consume किए। (?=…) positive lookahead है, (?!…) negative lookahead है, (?<=…) positive lookbehind है और (?<!…) negative lookbehind है। उदाहरण के लिए, \d+(?=px) '5px' में 5 match करता है लेकिन 'px' छोड़ देता है, और (?<=\$)\d+ '$9' में 9 match करता है एक preceding dollar sign require करके। Lookarounds वो features में से एक हैं जो modern regex engines को POSIX grep से अलग करते हैं।

Regex flags क्या होते हैं?

Flags change करते हैं कि पूरा pattern कैसे apply होता है: g (global) हर match find करता है, i इसे case-insensitive बनाता है, m (multiline) ^ और $ को हर line match करने देता है, s (dotall) . को newlines match करने देता है, u full Unicode enable करता है और y (sticky) matching को एक fixed position पर anchor करता है। JavaScript में आप उन्हें closing slash के बाद add करते हैं, तो /cat/gi text में हर जगह 'Cat' और 'CAT' match करता है। इस page पर tester में हर flag के लिए toggle buttons हैं ताकि आप उनका effect live देख सकें।

Email, phone number या URL के लिए regex कैसे लिखें?

Practical starting patterns: email — [\w.+-]+@[\w-]+\.[\w.-]+ ; URL — https?:\/\/[^\s]+ ; Indian mobile number — [6-9]\d{9}, जो 9876543210 जैसे numbers match करता है। ये pragmatic हैं, exhaustive नहीं — official email standard कहीं ज्यादा complex है — इसलिए इन्हें हमेशा ऊपर live tester में अपने असल data पर test करें, जहाँ हर एक Common patterns list में एक single click पर है।

Regex में special characters को escape कैसे करते हैं?

किसी भी metacharacter को literally match करने के लिए उसके आगे backslash लगाएं। जिन characters को usually escaping की जरूरत होती है वे हैं . ^ $ * + ? ( ) [ ] { } | \ और /। उदाहरण के लिए \. एक literal dot match करता है और \$ एक dollar sign match करता है, तो \d+\.\d{2} एक price जैसे 19.99 match करता है। एक character class के अंदर इनमें से ज्यादातर अपना special meaning खो देते हैं, तो [.] भी बिना escaping के एक literal dot match करता है।

JavaScript, Python और Java में regex flavors अलग-अलग होते हैं क्या?

Core syntax shared है, लेकिन details अलग हैं। JavaScript groups को (?<name>…) से name करता है जबकि Python (?P<name>…) use करता है; Python raw strings जैसे r"\d+" use करता है और Java को string literals में doubled backslashes चाहिए ("\\d+")। Dotall JS में s flag है, Python में re.DOTALL और Java में Pattern.DOTALL। इस page पर flavor table Python, Java, PCRE और grep के लिए differences summarize करता है ताकि आप एक pattern को languages के बीच confidently port कर सकें।

Python में regular expression कैसे use करते हैं?

Python में, regular expressions built-in re module में रहते हैं। आप usually pattern को raw string के रूप में लिखते हैं और re.search, re.findall या re.sub जैसे functions call करते हैं — उदाहरण के लिए re.findall(r"\d+", "a1 b22") ['1', '22'] return करता है। Named groups (?P<name>…) use करते हैं और उन्हें match.group('name') से read करते हैं। इस page का token reference सीधे Python regex पर apply होता है; केवल surrounding API और कुछ flag names JavaScript से अलग हैं।

Regex को test कैसे करें?

इस page के top पर live tester use करें: slashes के बीच अपना pattern type करें, जरूरी flags toggle करें, और एक test string paste करें। Matches real time में highlight होते हैं, हर numbered और named capture group नीचे break out होता है, और एक invalid pattern silently fail होने की जगह inline error message दिखाता है — सब कुछ locally आपके browser में चलता है, इसलिए जो भी आप paste करते हैं वो upload नहीं होता। regex101.com और regexr.com जैसे tools similarly काम करते हैं; यह reference और tester को एक page पर combine करता है।

यह regex101.com और regexr.com से कैसे compare करता है?

regex101.com deep regex debugging के लिए industry standard है — यह multiple flavors (PCRE, Python, Java, .NET, Golang) support करता है और आपके pattern में हर token की detailed explanation देता है। regexr.com भी patterns की community library के साथ similar experience offer करता है। दोनों excellent dedicated tools हैं। यह UtiloKit cheat sheet अलग है: यह एक token reference table को एक basic live tester के साथ same page पर pair करता है, ताकि आप कुछ look up कर सकें और इसे seconds में verify कर सकें बिना tabs switch किए। Complex production regex work के लिए, regex101.com का flavor comparison और detailed debugger hard to beat है; development के दौरान quick lookups के लिए, यह reference page तेज load होता है और किसी navigation की जरूरत नहीं।

इसे "regular expression" क्यों कहते हैं?

यह नाम formal language theory से आता है। 1950s में mathematician Stephen Kleene ने 'regular sets' describe किए — वो languages जिन्हें एक simple finite-state machine recognize कर सकती है — और उन्होंने जो notation use की वो regular expression के नाम से जानी गई। Modern regex engines backreferences और lookarounds जैसे features add करते हैं जो strictly 'regular' languages से परे जाते हैं, लेकिन historical नाम बना रहा।