YouTip LogoYouTip

Regexp Usage Summary

## Regular Expressions - Usage Summary The following lists some common regular expression usage summaries: ### Matching Basic Characters * Use ordinary character matching: Ordinary characters (such as letters, numbers, symbols) represent themselves in regular expressions, for example, to match "tutorial": `/tutorial/`. [Try it Β»](#) !(#) * Use metacharacter `.` to match any character: `.` represents matching any single character, for example, to match "cat" or "cbt": `/c.t/`. [Try it Β»](#) !(#) ### Matching Character Sets * Use character set matching: Use square brackets `[]` to represent a character set, matching any character in the set, for example, to match "cat", "bat", or "hat": `/at/`. [Try it Β»](#) !(#) * Use hyphen `-` to represent character range: Using hyphen `-` in a character set represents matching a range of characters, for example, to match lowercase letters "a" to "z": `//`. [Try it Β»](#) !(#) ### Matching Repetitions and Quantities * Use `*` to match zero or more: `*` represents matching the preceding pattern zero or more times, for example, to match "caat", "ct", or "cat": `/ca*t/`. [Try it Β»](#) !(#) * Use `+` to match one or more: `+` represents matching the preceding pattern at least once or more times, for example, to match "cat", "caat", "caaat", etc.: `/ca+t/`. [Try it Β»](#) !(#) * Use `?` to match zero or one: `?` represents matching the preceding pattern zero or one time, for example, to match "ct" or "cat": `/ca?t/`. [Try it Β»](#) !(#) * Use curly braces `{n}` to match fixed quantity: Using curly braces `{n}` represents matching the preceding pattern exactly n times, for example, to match "caat", "caat123", or "caataaa": `/ca{2}t/`. [Try it Β»](#) !(#) ### Using Special Characters and Escaping * Escape special characters: Use backslash `` to escape special characters, for example, to match "2+2=4": `/2+2=4/`. [Try it Β»](#) !(#) * Match boundaries and positions: Use special characters `^` and `$` to represent the start and end of a line respectively, for example, to match a string starting with "hello": `/^hello/`. [Try it Β»](#) !(#) ### Using Capturing Groups * Use parentheses `()` to create capturing groups: Use parentheses `()` to combine part of a regular expression pattern into a capturing group, which can extract or group matched content, for example, to extract the year from a date: `/(d{4})-d{2}-d{2}/`. [Try it Β»](#)-%5Cd%7B2%7D-%5Cd%7B2%7D) !(#) ### Using Character Escaping * Use backslash `` to escape special characters: For special characters in regular expressions, such as `*`, `+`, `?`, etc., use backslash `` for escaping, for example, to match a string containing a literal asterisk
← Regexp Metachar BBrowsers Edge β†’