Tags

Regular Expressions

Regular Expressions

0 lessons
1 problem
6 code snippets
1 question bank

regex

Practice Problems

1 problem

Regular Expression Matching

Not Started
Hard

Implement regular expression matching with support for '.' (matches any single character) and '*' (matches zero or more of the preceding element).

Dynamic Programming
Strings
Tabulation
Regular Expressions
Advanced

425

4

Code Snippets

6 snippets
Code Snippet

Convert a String to a URL Slug

Slugifying turns human titles like `"Côte d'Ivoire, 2025!"` into URL-safe segments like `'cote-d-ivoire-2025'`. Done well, it covers Unicode normalization, accent stripping, and edge punctuation; done poorly, it ships duplicate slugs or 404s. This snippet starts with a regex-only baseline, layers in `normalize('NFD')` for diacritics, and ends with a hardened version that collapses dashes and bounds the length.

JavaScript
strings
regex
utility

626

18

Easy
Code Snippet

Count Words in a String

Word counting drives reading-time estimates, character-budget warnings, and SEO meta-checks. The naive `str.split(' ').length` overcounts double spaces, miscounts empty input, and ignores non-Latin scripts entirely. This snippet starts with a regex-based whitespace split, hardens it against empty and whitespace-only input, then upgrades to `Intl.Segmenter` for locale-aware counting in Chinese, Japanese, and Thai where there are no spaces.

JavaScript
strings
regex
utility

827

22

Easy
Code Snippet

Escape HTML Special Characters

Inserting user input into HTML without escaping is the canonical XSS vector. The five characters `&<>"'` cover most rendering contexts, but attribute values, URL attributes, and `<script>` blocks each have stricter rules. This snippet starts with the minimal map every JS dev should memorise, adds an attribute-safe variant that also escapes the backtick, and ends with a note on when to reach for a real sanitiser like DOMPurify (without bundling it).

JavaScript
strings
regex
utility

1k

11

Medium
Code Snippet

Tiny Template String Formatter

Sometimes you need a templating helper that does not pull in handlebars or eta, just enough to substitute `{name}` placeholders against a values object. This snippet starts with a 5-line interpolator, adds escape support so literal braces survive, and ends with a tagged-template-literal version that gives you compile-time placeholder safety. Drop it into i18n strings, log formatters, or email subject lines.

JavaScript
strings
regex
js-template-literals
code-template

428

14

Medium
Code Snippet

Strip Accents and Diacritics

Removing accents from a string is the secret behind diacritic-insensitive search, slug normalization, and sort-key generation. The canonical answer is `normalize('NFD') + replace combining marks`, which works for Latin scripts, but locale-aware comparison and case-folding need richer tools. This snippet starts with the one-liner, adds a case-folded variant for matching, and ends with `Intl.Collator` for true locale-correct comparison.

JavaScript
strings
regex
js-web-apis

858

4

Medium
Code Snippet

String Tricks: Anagrams, Vowels, Masking, Extension Check, Find Duplicates, Extract Numbers

A grab-bag of small string utilities pulled from a much larger pool: inspecting strings (anagram check, find duplicate characters, distinguish literal from object), counting and scanning (vowels via regex, extract numbers, extension check), transforming (mask the middle, generate alphabet ranges), and order-aware tricks (remove adjacent duplicates, reverse only words longer than n). Each is short on its own; together they cover most of the string work that shows up in real code.

JavaScript
strings
string-manipulation
regex
loops

904

16

Medium