String Utilities
100% LocalReverse, repeat, pad, trim, truncate, extract emails/URLs/numbers, and more.
Paste text to reverse, repeat, pad, trim, or truncate. Extract emails, URLs, and numbers from mixed text.
Learn More
What is String Utilities?
Frequently Asked Questions
Technical Deep Dive
String Utilities
A comprehensive string manipulation toolkit with 16 live operations: reverse, repeat N times, pad left/right, trim variants, truncate with ellipsis, remove whitespace, count occurrences, extract numbers, extract emails, extract URLs, and word/char/line counts. All results update instantly as you type.
Built for Devs
Designed by people who use these tools in production every day.
Smart Defaults
Reasonable assumptions out of the box, every assumption overridable when you need it.
Workflow-Friendly
Pairs with your IDE, CI, and code review, output drops into commits and PRs cleanly.
Practical String Operations: Common Recipes
Every developer hits the same string transformations repeatedly: cleaning input, extracting data from logs, formatting output for display, reversing for one-off algorithms. This tool consolidates 16 of the most common ones into a single interface, so you don't have to remember the exact padStart signature or write the email regex from scratch. The point is to make these instant.
The 16 Operations
1. Reverse
Reverse the string by Unicode code points. Handles surrogate pairs correctly so emoji don't break.
Used for: palindrome checks, certain algorithm exercises, debugging endianness.
2. Repeat N
Repeat the string N times.
Used for: building test data ("a".repeat(1000)), separator lines ("โ".repeat(80)), indentation.
3. Pad Left / Pad Right
Pad to a fixed width. Pad-left right-aligns; pad-right left-aligns.
Used for: aligned text output, fixed-width fields, zero-padded IDs.
4. Trim / Trim Start / Trim End
Remove whitespace from both/start/end. Whitespace includes spaces, tabs, newlines, and Unicode whitespace.
Used for: cleaning user input, parsing CSV cells, normalizing log lines.
5. Remove All Whitespace
Strip every whitespace character.
Used for: compact representations, comparison normalization, hashing input.
6. Truncate with Ellipsis
Cut to N characters, append โฆ if truncated.
Used for: previews, table cells, mobile display.
7. Count Occurrences
Count a substring inside the input.
Used for: log analysis, simple frequency checks.
8. Extract Numbers
Pull all numeric substrings.
Used for: parsing semi-structured text, extracting metrics from logs.
9. Extract Emails
Pull email-shaped substrings.
Used for: scraping contacts from text (with permission), log auditing.
10. Extract URLs
Pull URL-shaped substrings.
Used for: link auditing, log analysis.
11-13. Counts
- Characters: code-point count.
- Words: whitespace-separated tokens.
- Lines: line count (newline-separated).
14-16. Case operations
(Some tools include these; case-converter has its own page in this app.)
Common Recipes Beyond the Built-Ins
Strip non-alphanumeric
For slug generation, comparison normalization.
Word frequency
For text analysis, finding most common terms.
Levenshtein distance
Edit distance between two strings. Use a library, the O(mn) dynamic programming is a chore to write correctly.
Splitting a CSV line correctly
Naive line.split(',') breaks on quoted commas. Use a parser library.
Highlighting search matches
For search UIs (be sure to HTML-escape text first if rendering as HTML).
Unicode Awareness
Code units vs code points vs graphemes
| Concept | What it is | Example |
|---|---|---|
| Byte | One octet | UTF-8 emoji = 4 bytes |
| Code unit (UTF-16) | 16 bits | Emoji = 2 code units (surrogate pair) |
| Code point | One Unicode character | ๐ = 1 code point (U+1F600) |
| Grapheme cluster | One user-perceived character | ๐จโ๐ฉโ๐ง = 1 grapheme, 5 code points |
JavaScript's string.length and many built-ins operate on code units. For user-facing length, you usually want graphemes (Intl.Segmenter since 2022).
Examples
For sorting, comparison, and most operations, use locale-aware APIs: Intl.Collator, String.prototype.localeCompare. ASCII-only sort gives wrong results for non-English.
Normalization
Different code-point sequences can represent the same visual character. รฉ can be U+00E9 (single code point) or U+0065 U+0301 (e + combining acute). Compare with s.normalize('NFC') first.
NFC (composed) is the most common normalization for display/storage; NFD (decomposed) is sometimes wanted for stripping accents.
Common Pitfalls
Naive reverse breaks emoji and combining marks
str.split('').reverse().join('') corrupts surrogate pairs. Use [...str].
Substring index off by one
slice(start, end) is end-exclusive. 'hello'.slice(0, 3) is "hel", not "hell". Different languages have different conventions.
Regex flags
g(global): find all matches; affectsreplace,matchAll.i(case-insensitive).m(multiline):^/$match line boundaries.s(dotall):.matches newline.u(unicode): treat surrogate pairs as one character.y(sticky): match atlastIndexonly.
Without g, replace only replaces the first match. Common bug.
Case mapping in Unicode
'I'.toLowerCase() is "i" in English but "ฤฑ" (dotless) in Turkish locales. Use toLocaleLowerCase(locale) when locale matters.
'ร'.toUpperCase() is "SS" (two characters from one). Length changes.
Trim doesn't remove all "blank" characters
Unicode has many whitespace characters: U+00A0 (NBSP), U+200B (zero-width space), U+FEFF (BOM). trim() removes most but not all. For aggressive trim, use a regex: str.replace(/^[\s\u00A0\u200B\uFEFF]+|[\s\u00A0\u200B\uFEFF]+$/g, '').
Truncating breaks emoji or graphemes
str.slice(0, 50) may cut a surrogate pair or split a combining mark. For user-facing text, use Intl.Segmenter to find safe boundaries.
Regex Snippets for Extraction
| Target | Pattern |
|---|---|
| Emails (pragmatic) | /[\w.+-]+@[\w-]+\.[\w.-]+/g |
| URLs (pragmatic) | /https?:\/\/[^\s<>"]+/g |
| IPv4 | /\b\d{1,3}(?:\.\d{1,3}){3}\b/g |
| Phone (US, pragmatic) | /\b\d{3}[-.\s]?\d{3}[-.\s]?\d{4}\b/g |
| Hex colors | /#(?:[0-9a-fA-F]{3,4}){1,2}\b/g |
| ISO date | /\b\d{4}-\d{2}-\d{2}\b/g |
| Numbers (with decimals, negatives) | /-?\d+(?:\.\d+)?/g |
| Words | /\w+/g |
"Pragmatic" = covers 95% of real-world cases; exotic edge cases (quoted emails, IPv4 in URLs, etc.) may slip through. Validation = strict pattern; extraction = pragmatic pattern.
Performance Notes
JavaScript strings are immutable; every operation produces a new string. For long pipelines on long strings, prefer doing the work in one pass when possible. For genuinely large text (>10 MB), JS becomes slow, use streaming or move to a backend tool.
String.prototype.replace with a function callback is the most flexible, replaces with computed values. Faster than multiple regex passes.
String.prototype.matchAll (ES2020+) returns an iterator of match objects, including groups and indices. Easier than the older .match(/regex/g) for capture groups.
Privacy
All operations run as JS string methods in your browser, no upload, no proxy, no logging. Open DevTools Network during use: zero outbound requests. Strings frequently contain sensitive context (PII in extracted emails, internal URLs in log fragments, proprietary terms in customer data); sending them to a server would defeat the purpose. This tool runs everything locally.