Regular Expression: Difference between revisions

From Ideasplace
Jump to navigation Jump to search
mNo edit summary
Line 56: Line 56:
| '''Escaping''' || <code>\</code> || Backslash || Treats special characters as text || <code>\.</code> || "." (actual dot)
| '''Escaping''' || <code>\</code> || Backslash || Treats special characters as text || <code>\.</code> || "." (actual dot)
|}
|}
* [https://regex101.com/ Regex101]
* [https://regexr.com/ RegexR]

Revision as of 17:48, 23 January 2026

Category Symbol Name Meaning Example Matches
1. Wildcards & Character Classes
Matching Characters (text) Literal Matches exact text cat "cat"
. Dot Matches any single character (except newline) h.t "hat", "hot"
[ ] Brackets List of allowed characters b[ai]t "bat", "bit"
[^ ] Negation Matches anything NOT in the list [^a] Any char except 'a'
\d Digit Any number 0-9 \d\d "42", "99"
\w Word Char Letter, number, or underscore \w+ "User_1"
\s Space Whitespace (space, tab, enter) A\sB "A B"
2. Quantifiers (How Many?)
Counting * Star 0 or more times go*d "gd", "god"
+ Plus 1 or more times go+d "god", "good"
? Question 0 or 1 time (Optional) colou?r "color", "colour"
{n} Exact Count Matches exactly n times \d{3} "123"
{n,} Min Count Matches n or more times \d{3,} "123", "12345"
{n,m} Range Matches between n and m times \d{2,4} "12", "1234"
.*? Lazy Match Matches as little as possible <.*?> Stops at first matching char
3. Anchors & Boundaries (Where?)
Positioning ^ Caret Start of string/line ^The Starts with "The"
$ Dollar End of string/line end$ Ends with "end"
\b Word Boundary The edge of a word (start or end) \bcat\b "cat" (not "scat")
4. Groups & Logic
Logic Pipe OR logic (Alternative) dog "cat" or "dog"
(...) Group Groups characters or captures them b)c "ac" or "bc"
5. Special Characters
Escaping \ Backslash Treats special characters as text \. "." (actual dot)