User Rating 0.0 โ˜…โ˜…โ˜…โ˜…โ˜…
Total Usage 0 times
Input
0 characters
Output
Presets:
Is this tool helpful?

Your feedback helps us improve.

โ˜… โ˜… โ˜… โ˜… โ˜…

About

Handling number ranges in configuration files, pagination systems, or data pipelines introduces parsing ambiguity. A string like "1-5, 8, 10-12" must expand to exactly 9 discrete values, but edge cases - negative bounds, descending order, step intervals, duplicate elimination - cause silent data corruption if handled naively. This tool implements a bidirectional parser: it expands range strings into sorted, deduplicated arrays, and collapses integer arrays back into minimal range notation. The parser handles step syntax (e.g., 1-10:2), negative ranges (e.g., -5--1), and configurable delimiters. Approximation: this tool assumes integer-only inputs and does not handle floating-point ranges.

range to array array to range rangify number range converter expand ranges collapse ranges range parser

Formulas

The expansion algorithm for a range token A-B:S generates the set:

R = { A + i โ‹… S โ‹… d | i โˆˆ Zโ‰ฅ0, |A + i โ‹… S โ‹… d| โ‰ค |B| }

where d = sign(B โˆ’ A) determines direction (1 for ascending, โˆ’1 for descending), and S defaults to 1 if omitted.

The collapse algorithm scans a sorted array and groups consecutive integers into range tokens. A consecutive sequence ai, ai+1, โ€ฆ, aj where ak+1 โˆ’ ak = 1 for all k is collapsed to ai-aj only if (j โˆ’ i + 1) โ‰ฅ M, where M is the minimum range length (default 3).

Reference Data

Input PatternSyntaxExample InputExpanded OutputNotes
Single valueN5[5]Passed through as-is
Simple rangeA-B1-5[1,2,3,4,5]Inclusive on both ends
Descending rangeA-B where A > B5-1[5,4,3,2,1]Produces descending order
Stepped rangeA-B:S1-10:2[1,3,5,7,9]Step S must be positive integer
Negative single-N-3[-3]Leading minus sign
Negative range-A--B-5--1[-5,-4,-3,-2,-1]Double dash separates negative bounds
Mixed signs-A-B-2-3[-2,-1,0,1,2,3]Crosses zero boundary
Comma-separated listA, B, C1, 3, 7[1,3,7]Whitespace around commas ignored
Mixed list & rangesA, B-C, D1, 3-5, 9[1,3,4,5,9]Free mixing allowed
DuplicatesA, A1-3, 2-4[1,2,3,4]Duplicates removed automatically
Large rangeA-B1-1000[1,2,...,1000]Capped at 100000 elements for safety
Collapse: consecutiveArray โ†’ String[1,2,3,5]1-3, 5Groups of โ‰ฅ3 collapsed by default
Collapse: single gapsArray โ†’ String[1,2,5,6]1-2, 5-6Min range size configurable
Newline delimiterOne entry per line1-3\n5\n8-10[1,2,3,5,8,9,10]Newline acts as comma
Semicolon delimiterA;B1-3;5;8[1,2,3,5,8]Custom delimiter support

Frequently Asked Questions

The parser uses a context-aware tokenizer that distinguishes between a minus sign acting as a unary negation operator and one acting as a range separator. When it encounters a pattern matching the regex for a signed integer followed by a dash and another signed integer, it correctly splits on the range dash. For example, -5--1 is parsed as start = โˆ’5, end = โˆ’1, producing [โˆ’5, โˆ’4, โˆ’3, โˆ’2, โˆ’1].
Overlapping ranges are automatically deduplicated. The tool expands all range tokens independently, merges the resulting arrays, removes duplicates using a Set, and then sorts the final array in ascending order. For input 1-5, 3-7, the output is [1,2,3,4,5,6,7] - exactly 7 unique values, not 10.
Yes. The tool enforces a safety cap of 100,000 total expanded elements to prevent browser tab crashes from memory exhaustion. If a single range like 1-500000 or accumulated ranges exceed this limit, the tool reports an error and refuses to expand. For large datasets, consider processing in chunks.
Step notation generates every S-th value in the range. 0-20:5 produces [0, 5, 10, 15, 20]. The step value must be a positive integer โ‰ฅ 1. If the step does not evenly divide the range, the last generated value is the largest multiple of S from A that does not exceed B (or fall below B for descending).
The algorithm uses a configurable minimum range length parameter M (default 3). A consecutive sequence is only collapsed into range notation if it contains โ‰ฅ M elements. With M = 3, the pair [5, 6] stays as 5, 6, but [5, 6, 7] becomes 5-7. Setting M = 2 collapses even pairs.
Yes. The tool supports comma, semicolon, space, pipe, and newline as input delimiters. Select the desired delimiter from the settings panel. The output delimiter in collapse mode is independently configurable. This is useful when converting between formats - for example, parsing semicolon-separated ranges from a CSV column and outputting comma-separated arrays for JSON.