按数字范围提取🐠meeeyo.com
Cut a string by character range instead of guessing a regex
- STRING
Sometimes you don't know what's at position N - you just know position N is where the data starts. ExtractSubstringByIndices (按数字范围提取 - "extract by numeric range") is the node for that: it slices a string by character position, plain and literal, no patterns to escape and no regex to debug. If the text you're parsing is fixed-width or comes from a generator that always puts the value in the same spot, this is the cleanest cut in the ComfyUI_StringOps pack.
How it works
Two real inputs: input_string and indices. The indices field takes a range like 2-6, and the node returns characters 2 through 6. Couple of details that matter:
- 1-based, not 0-based.
2-6means the second character through the sixth. If you're used to Python slicing, mentally add one to everything. - A single number works too.
indices = 4(no dash) grabs just the fourth character. - Out-of-range is forgiving. If the end index runs past the string, it clamps to the end; if the start is out of bounds, you get an empty string rather than a crash.
- Swapped bounds self-correct.
6-2and2-6give the same result.
Then there's direction, a two-choice dropdown: 从前面 (from the front) or 从后面 (from the back). The front mode counts from the left end; the back mode counts from the right end. So with hello world and indices 6-6 from the back, you're grabbing a character 6 from the end rather than the sixth character. It's a genuinely useful shortcut for "give me the last N characters" - --style negative indexing without having to compute the length yourself.
Why it exists in a string pack
The StringOps pack leans hard on pattern and rule-based extraction (ExtractSubstring, ExtractBeforeAfter, ExtractSpecificData). This node covers the other end of the spectrum: position-based cutting for when the text is structurally predictable. Think timestamps in a fixed format, padded IDs, or a caption where the interesting part is always characters 10–18. One node, no regex.
Install
Standard StringOps install, same as the rest of the pack:
cd ComfyUI/custom_nodes
git clone https://github.com/MeeeyoAI/ComfyUI_StringOps.git
Restart, done. Or ComfyUI Manager → search "ComfyUI_StringOps". No model files, no heavy deps - pure string manipulation. UI is Chinese (提取标签之间 is the sibling node; this one's 按数字范围提取), with the usual 🐠meeeyo.com branding and an ad in the description.
Common issues
The off-by-one is the classic. Since it's 1-based, 1-3 includes the first character - plenty of people port a 0-based habit over and lose the first character every time. Second: whitespace counts as a character. If your string has leading spaces, your range grabs them too, and you'll stare at output that looks "empty" until you notice it. And remember it operates on characters, not words - for word-count filtering, that's FilterLinesByWordCount's job elsewhere in this pack.
It's a thin, honest utility. If you never parse fixed-format strings you may never need it; if you do, it's the one you'll remember.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| input_string | STRING | — | |
| indices | STRING | 2-6 | — |
| direction | COMBO | 从前面 | 2 options: 从前面, 从后面 |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| STRING | STRING | — |