REGEX TESTER

/ /
Flags:
Common patterns:
0 characters ยท 0 lines
$1 = group 1 ยท $& = poora match ยท $$ = literal $
Matches
#MatchIndexLengthGroups

REGEX KYA HOTA HAI โ€” POORA GUIDE

Regular expression (ya regex) ek chhota sa pattern hai jo text me dhundne ka kaam karta hai. Ek hi pattern hazaron lines me se sirf wahi hissa uthata hai jo aapki shart poora karta hai โ€” aur wo shart itni simple ho sakti hai jitni "yahan se shuru ho" ya "sirf email address pakdo".

Sabse zyada use hone wale 12 symbols

SymbolMatlabExample
.ek bhi character (newline ke alawa)a.c โ†’ "abc", "axc"
\dek digit\d{3} โ†’ "302"
\wword character (letter, digit, underscore)\w+ โ†’ "hello_1"
\skoi bhi whitespacea\s+b โ†’ "a b"
*0 ya zyada baarab*c โ†’ "ac", "abc", "abbbc"
+1 ya zyada baarab+c โ†’ "abc", "abbc"
?0 ya 1 baarab?c โ†’ "ac", "abc"
{n}exactly n baar\d{6} โ†’ PIN code
[abc]in me se koi ek[aeiou] โ†’ vowels
[^abc]in me se koi bhi nahi[^0-9] โ†’ non-digit
|ya (alternation)cat|dog
^ $line ki shuru aur khatam^\d{5}$

Capturing groups

Bracket se aap pattern ka koi hissa alag se pakad sakte ho, aur wo captured group replacement me $1, $2 se wapas aa jaata hai. Date nikaalne wala pattern dekhiye:

(\d{4})-(\d{2})-(\d{2}) โ€” yahan $1 saal, $2 mahina aur $3 din hai. Ye teen hissa alag-alag columns me daalne ke liye $1\t$2\t$3 likh kar replace karein.

Greedy vs Lazy โ€” sabse common galti

Quantifier by default greedy hota hai, yaani jitna ho sake utna pakadta hai. Isliye <.+> HTML tag nikaalne me poori line kheench leta hai. Usko lazy banane ke liye quantifier ke baad ek question mark lagayein: <.+?>. Ab wo pehla closing angle bracket par ruk jaata hai.

Look-ahead aur look-behind

Kabhi aap match ko test karna chahte ho bina usse consume kiye. Iske liye look-ahead hota hai: (?=...) aage dekhta hai, (?!...) aage dekhta hai ki match nahi hona chahiye. Look-behind (?<=...) peeche dekhta hai. Example: password me kam se kam 8 character aur ek number:

^(?=.*\d)(?=.*[a-z]).{8,}$ โ€” do look-ahead saath me lagte hain, dono true hote hi baaki pattern chalega.

Inline flags aur named groups

Poore pattern me case-insensitivity chahiye to shuru me (?i) likh sakte ho, sirf ek hisse me chahiye to (?i:...). Named groups syntax se padhne layak hote hain โ€” JavaScript me (?<year>\d{4}) aur baad me groups.year. Group ki position yaad rakhne se zyada naam yaad rakhna asaan hai.

Security note

Ek regex jo bahut zyada backtrack kare, jaise koi nested quantifier pattern, untrusted input par CPU pakad sakta hai โ€” isse ReDoS kehte hain. Agar aap user ka data apne server par regex chala kar validate kar rahe ho to pattern ko timeout ke saath chalaayein aur nested quantitators se bachein. Is tool me matching aapke browser me hoti hai, isliye yahan server ka koi risk nahi hai.

REGEX TESTER โ€” SAWAAL JAWAAB

Frequently Asked Questions (FAQ)

It compiles your pattern with JavaScript regular expressions, then reports every match in your test text with the exact position, length and captured group values. Matches are highlighted in the text area as you type, so you can see what the pattern does rather than guessing. Nothing is sent anywhere; all matching runs inside your browser.

That error means the parenthesis in the pattern are unbalanced, or a back reference points to a group that does not exist. Each opening bracket needs exactly one closing bracket, and a back reference is written as a backslash followed by the group number, such as backslash one, which refers to the first captured group. The tester tells you which character position the parser choked on so you can jump straight there.

The g flag makes the tester collect every match instead of stopping at the first. The i flag makes matching ignore letter case. The m flag lets the anchors for line start and line end match at each new line rather than only the whole string. The s flag lets the dot match newlines too. The u flag enables full Unicode handling, which you need for emoji, non-Latin scripts and modern features like named groups.

A question mark after a quantifier makes it lazy, which means it matches as little as possible, while the default greedy behaviour matches as much as possible. For the pattern that captures digits, a greedy match takes the entire number. Adding a question mark to close it makes it stop at the first possible end, which is exactly what you want when matching a zip code or a year, where the following character should not be swallowed.

Use the dot-all flag together with a lazy quantifier, for example a pattern that matches everything lazily up to a closing marker. The lazy part stops at the first closing marker rather than running to the last one, and the dot-all flag lets the dot cross newlines. Without the dot-all flag the pattern simply will not match anything that contains a line break.

No, and this trips people up constantly. The pattern side is a regular expression, but the replacement side supports a separate, simpler set of tokens. A dollar sign followed by a number inserts that captured group, a dollar sign followed by an ampersand inserts the entire matched text, and a dollar sign followed by a name inserts a named group. To output a literal dollar sign you write two of them.

Because no regular expression can fully validate an email address. You can match the obvious structure, which is what most patterns do, but the real test is whether the domain has a mail exchanger record and whether the mailbox exists. For form validation a structural pattern is enough, and the checker in the tester will tell you what your current pattern lets through so you can see the gaps yourself.

Yes. The whole tool is a single page with no server round trip for matching, so it works the same on a phone. The panels stack vertically on small screens and the pattern and test text fields both stay usable with a soft keyboard.

It uses the JavaScript flavour, which is very close to the others and covers what most people need: character classes, quantifiers, groups, alternation, anchors and look-ahead. The differences show up in named-group syntax, where Python uses a question mark and equals sign inside the brackets but JavaScript uses angle brackets, and in escape handling inside character classes. If you are porting a pattern, check the named group syntax first.

The most common reason is the newline behaviour. Without the multiline flag, the start and end anchors only match the very beginning and very end of the whole string, so anchoring a pattern on each line silently fails. The second most common reason is invisible characters, such as a non-breaking space or a zero width space copied from a website, which look like ordinary spaces but are not matched by a plain space.
Rate this tool: 5.0 (0)