Regex Tester
Test, debug, and learn regular expressions with real-time text matching, syntax highlighting, and detailed cheat sheets right in the browser. Ele roda inteiramente no seu navegador — nenhum dado é enviado para nenhum servidor, nenhuma conta é necessária e é totalmente gratuito.
The Complete Guide to Regular Expressions (Regex)
Regular expressions — regex or regexp for short — are one of the most powerful and most feared tools in a programmer's arsenal. A single regex can replace dozens of lines of string-parsing code, validate complex input formats, extract structured data from unstructured text, and perform find-and-replace operations that would otherwise require loops and conditionals. Our free online Regex Tester lets you write, test, and debug regular expressions in real time using the JavaScript ECMAScript regex engine.
Regex Syntax: The Core Building Blocks
Literal Characters
The simplest regex is just a literal string. The pattern hello matches the exact sequence of characters "hello" anywhere in the input text. Most characters match themselves literally.
Special Characters (Metacharacters)
These characters have special meaning in regex and must be escaped with a backslash \ to match them literally:
. ^ $ * + ? { } [ ] \ | ( )
For example, to match a literal period, use \. — because unescaped . matches any single character.
The Dot: Match Any Character
. matches any single character except a newline. c.t matches "cat", "cut", "cot", "c3t", "c t", but NOT "ct" (nothing between c and t).
Character Classes [ ]
Square brackets define a set of characters, any one of which can match at that position:
[aeiou]— matches any single vowel[0-9]— matches any single digit (range syntax)[a-zA-Z]— matches any uppercase or lowercase letter[^aeiou]— the^inside[]negates — matches any character that is NOT a vowel
Shorthand Character Classes
\d— digit: equivalent to[0-9]\D— non-digit: equivalent to[^0-9]\w— word character: equivalent to[a-zA-Z0-9_]\W— non-word character\s— whitespace: space, tab, newline, carriage return\S— non-whitespace
Anchors: Matching Position, Not Characters
^— matches the start of a string (or start of a line withmflag)$— matches the end of a string (or end of a line withmflag)\b— word boundary: matches the position between a word character and a non-word character\B— non-word boundary
Quantifiers: How Many Times?
*— zero or more times+— one or more times?— zero or one time (makes it optional){3}— exactly 3 times{2,5}— between 2 and 5 times{3,}— 3 or more times
Greedy vs Lazy: By default, quantifiers are greedy — they match as much as possible. Adding ? after a quantifier makes it lazy — it matches as little as possible. Example: given <b>bold</b>, the pattern <.*> greedily matches the entire string, while <.*?> lazily matches just <b>.
Groups and Alternation
(abc)— capturing group: groups the pattern and captures the match for backreference(?:abc)— non-capturing group: groups without capturing (more efficient)a|b— alternation: matches either "a" or "b"\1— backreference: matches the same text that group 1 captured
Regex Flags (Modifiers)
g(global) — find all matches, not just the firsti(case-insensitive) —Hellomatches "hello", "HELLO", "HeLLo"m(multiline) —^and$match start/end of each line, not just the whole strings(dotAll) — makes.match newline characters toou(unicode) — treat pattern as Unicode code points
Essential Real-World Regex Patterns
- Email:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$ - US Phone:
^\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$ - URL:
https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*) - Date (YYYY-MM-DD):
^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ - IPv4 Address:
^(\d{1,3}\.){3}\d{1,3}$ - Hex Color:
^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$ - Strong Password:
^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$
Use our free Regex Tester to write, test, and debug regular expressions in real time. For string manipulation tasks, also try our Text Diff Checker and Case Converter.
Como usar a Regex Tester
- 1
Write Pattern
Enter your regular expression pattern in the first input box, without the enclosing slashes.
- 2
Set Flags
Enter regex flags (like g for global, i for case-insensitive, m for multiline) in the second small box.
- 3
Test String
Type or paste your test text in the left text area. Matches will instantly highlight in the right panel.
Perguntas Frequentes
What is a Regular Expression (Regex)?
A regular expression is a sequence of characters that specifies a search pattern in text. Usually such patterns are used by string-searching algorithms for "find" or "find and replace" operations.
Does this execute on a server?
No. All regex matching happens instantly in your browser using the native JavaScript regex engine (ECMAScript flavor).