Regex Tester & Visualizer
Paste a JavaScript regular expression, type a test string, and see matches highlighted instantly. Built for beginners who want regex results and simple explanations without opening five tabs.
Matched Strings
Plain English Explanation
What is Regular Expression (Regex)?
A regular expression, usually shortened to regex, is a pattern used to find, validate or replace text. Developers use regex to check emails, extract phone numbers, validate usernames, parse logs, search code and clean messy text. Instead of manually checking every character, you describe the pattern once. For example, \d+ means one or more digits, while [a-z]+ means one or more lowercase letters.
Regex looks cryptic at first because many symbols carry special meaning. A dot means any character, a plus means one or more, square brackets define a character set, and parentheses create groups. The best way to learn regex is by testing small patterns and watching what they match. That is why this page highlights matches in real time and shows the exact matched strings below the editor.
Common Regex Patterns Explained (Emails, Phone numbers)
Email regex usually looks for text before an @, a domain name, and an extension such as .com or .in. A beginner-friendly email pattern is [\w.-]+@[\w.-]+\.\w+. It is not perfect for every possible email address, but it works well for many practical forms and demos. Phone regex depends heavily on the country. For India, you may test patterns like (\+91[\s-]?)?[6-9]\d{9} for many mobile numbers.
Remember that regex validation should match your real use case. A strict production form may need different rules than a quick search tool. When in doubt, start broad, test examples, and then tighten the pattern carefully.
JavaScript Regex Methods
JavaScript supports regex through the RegExp object and methods on strings. test() returns true or false when a pattern is found. match() returns matched text. matchAll() is useful when you want every match and capture group. replace() can swap matched text with something else. This tool uses JavaScript regex behavior, so flags like g, i, m, s, u and y behave the way they do in modern browsers.
Real Example
Suppose a signup form needs to validate Indian mobile numbers before sending an OTP. A practical pattern is ^(?:\+91[\s-]?)?[6-9]\d{9}$. The ^ and $ anchors require the entire input to match, rather than finding a phone number inside a longer sentence. The optional group (?:\+91[\s-]?)? accepts the Indian country code, with an optional space or hyphen after it. Next, [6-9] requires the first mobile digit to be 6, 7, 8, or 9, and \d{9} requires exactly nine more digits. In the tester, 9876543210, +91 9876543210, and +91-9123456789 should pass. 5123456789 fails because Indian mobile numbers in this simplified rule cannot begin with 5. 987654321 fails because it has only nine digits, while +91 98765 43210 fails because this particular pattern allows formatting only after the country code. For production, decide whether you want to normalize spaces first and always verify ownership by OTP; regex checks format, not whether a number is active.
FAQ
Does this regex tester send my text to a server?
No. The regex matching runs in your browser using JavaScript and Ace Editor. Your test string is not uploaded by this tool.
Can I use slash syntax like /abc/gi?
Yes. You can type slash-style patterns such as /[a-z]+/gi, or type only the raw pattern such as [a-z]+.
Why does my regex behave differently in another language?
Regex engines differ slightly across JavaScript, Python, PHP, Java and other languages. This tester follows JavaScript regular expression rules.