Issue with extractregex() inside {run} in Text Blaze

When using extractregex() inside a {run} command in Text Blaze, if the target value is missing in the input text, the entire script stops executing at that point. This means that any {run} commands placed after a missing value do not run.

To work around this, we have to write each {run} command separately, which is inconvenient and makes the script longer and harder to maintain.

Expected Behavior
If extractregex() does not find a match, it should return an empty string ("") or null, and execution should continue with the next {run} command instead of stopping entirely.
Current Workaround (Inefficient)
To avoid stopping execution, each {run} command must be written separately:

{run: wbc=extractregex({=chart},"White Blood Cell Count\s*[HL]?\s*([\d.]+)\s*/MCL")}
{run: rbc=extractregex({=chart},"Red Blood Cell Count\s*[HL]?\s*([\d.]+)\s*X10000/MCL")}
{run: hgb=extractregex({=chart},"Hemoglobin\s*[HL]?\s*([\d.]+)\s*G/DL")}
{run: hct=extractregex({=chart},"Hematocrit\s*[HL]?\s*([\d.]+)\s*%")}
{run: ldl=extractregex({=chart},"LDL Cholesterol\s*[HL]?\s*([\d.]+)\s*MG/DL")}
{run: hdl=extractregex({=chart},"HDL Cholesterol\s*[HL]?\s*([\d.]+)\s*MG/DL")}

This approach works, but it is cumbersome when handling many fields.

Problematic Example (Fails)
If we attempt to combine multiple extractions inside a single {run}, execution stops at the first missing value:

{run: 
wbc=extractregex({=chart},"White Blood Cell Count\s*[HL]?\s*([\d.]+)\s*/MCL")
rbc=extractregex({=chart},"Red Blood Cell Count\s*[HL]?\s*([\d.]+)\s*X10000/MCL")
hgb=extractregex({=chart},"Hemoglobin\s*[HL]?\s*([\d.]+)\s*G/DL")
hct=extractregex({=chart},"Hematocrit\s*[HL]?\s*([\d.]+)\s*%")
ldl=extractregex({=chart},"LDL Cholesterol\s*[HL]?\s*([\d.]+)\s*MG/DL")
hdl=extractregex({=chart},"HDL Cholesterol\s*[HL]?\s*([\d.]+)\s*MG/DL")
}

If rbc is missing from {=chart}, the execution stops, and hgb, hct, ldl, and hdl are never extracted.

Proposed Solution
Modify extractregex() so that when no match is found, it returns an empty string ("") instead of stopping execution.
Allow a default value option, e.g., extractregex({=chart},"LDL Cholesterol\s*([\d.]+)\s*MG/DL", ""), so missing values do not cause execution failure.
Ensure {run} continues executing even if a value is missing.

This issue makes it difficult to handle structured text extraction efficiently. A built-in solution to allow {run} to continue execution even when extractregex() fails to match would significantly improve usability.

Would appreciate any insights or potential fixes from the Text Blaze team!

Hey @N_Saito,
Welcome to the community.

In this case, you would want to enclose the extractregex formula inside a catch command so that the run continues to execute. Sharing an example snippet here. You can also read more about catch command here.

{run: wbc=catch(extractregex({=chart},"White Blood Cell Count\s*[HL]?\s*([\d.]+)\s*/MCL"), "Not found")
rbc=catch(extractregex({=chart},"Red Blood Cell Count\s*[HL]?\s*([\d.]+)\sX10000/MCL"),"Not found")
hgb=catch(extractregex({=chart},"Hemoglobin\s
[HL]?\s*([\d.]+)\sG/DL"),"Not found")
hct=catch(extractregex({=chart},"Hematocrit\s
[HL]?\s*([\d.]+)\s*%"),"Not found")
ldl=catch(extractregex({=chart},"LDL Cholesterol\s*[HL]?\s*([\d.]+)\sMG/DL"), "Not found")
hdl=catch(extractregex({=chart},"HDL Cholesterol\s
[HL]?\s*([\d.]+)\s*MG/DL"), "Not found")}

2 Likes

@Samay_Jain
It worked fine with the modified code, thank you.