Nodes/LF Nodes/Extract string
ComfyUI Node

Extract string

One substring, pulled out and typed five different ways

By lucafoscili·Created 2 years ago·Updated about a year ago· 50
Extract string
  • ui_widget
  • result_as_json
  • extracted_text
  • result_as_int
  • result_as_float
  • result_as_boolean
text
starting_delimiter{
ending_delimiter}

Pulling one specific value out of a bigger string is a common enough need that most workflows end up with some regex or split logic buried in a node somewhere, followed by a separate cast node depending on what type the next thing wants. LF_ExtractString does the extraction and the type conversion in one step - it hands back the same extracted text as five different types simultaneously, so you wire whichever one your downstream node actually needs.

The mechanism: give it text, plus starting_delimiter and ending_delimiter (defaulting to { and }), and it grabs whatever sits between the first matching pair of those delimiters. That's genuinely the whole extraction logic - it's a delimiter-bounded substring pull, not a general pattern matcher, so if you need actual regex-style matching, LF_RegexReplace is the right tool instead.

Where it earns its place is the five outputs: extracted_text (the raw substring, untouched), result_as_json (parsed as JSON, if the extracted text is valid JSON), result_as_int, result_as_float, and result_as_boolean. You don't need all five - wire only the one matching the shape of what you actually extracted, and leave the rest unconnected. Pulling a number out of a larger template string and feeding LF_MathOperation? Use result_as_int or result_as_float directly, no separate cast node needed. Pulling a JSON fragment out of something LF_LoadMetadata returned? result_as_json is ready to go.

Think of the delimiters as a lightweight alternative to writing a regex for a job that's usually simpler than it feels: most of the time you're not matching a complex pattern, you just want "the thing between these two markers," and this node covers that without asking you to think in regex syntax at all. It pairs naturally with LF_StringTemplate too - if your template output embeds a value in brackets somewhere for later extraction, this is the node that pulls it back out on the other end.

Installing it. ComfyUI Manager: search "LF Nodes," install, restart. Manual: cd ComfyUI/custom_nodes && git clone https://github.com/lucafoscili/lf-nodes, then restart. Use that repo - comfyui-lf, the one comfy.icu links, is the pack's archived original home; the author's active development is at lf-nodes. No models, no heavy dependencies.

Where people get tripped up. The schema doesn't document what happens when your extracted text doesn't actually match the type you're reading from - say you extract "hello" and wire result_as_int downstream. Don't assume a graceful fallback; wire the output that actually matches the shape of what you're extracting, and treat mismatched types as a real risk of an execution error rather than a silent empty value. Second, this pulls from the first matching delimiter pair only - if your text has multiple {...} sections and you need a specific one, not the first, you'll need to narrow text down before it reaches this node, or adjust which delimiters you're matching on.

Category✨ LF Nodes/Logic

Inputs (4)

NameTypeDefaultDescription
textSTRINGThe string from which the output will be extracted.
starting_delimiterSTRING{The delimiter where extraction starts.
ending_delimiterSTRING}The delimiter where extraction ends.
ui_widgetoptKUL_CODE

Outputs (5)

NameTypeDescription
result_as_jsonJSON
extracted_textSTRING
result_as_intINT
result_as_floatFLOAT
result_as_booleanBOOLEAN