uCalc API Version: 2.1.3-preview.2 Released: 6/16/2026

Warning

uCalc API Preview Release Notice:The documentation describes the intended behavior of the API. The current preview build contains incomplete features, unoptimized performance, and is subject to breaking changes.

Pattern Best Practices & Pitfalls

Product: 

Class: 

Remarks

In a pattern, the curly brace has special meaning. If you actually want to capture a literal curly brace, and not have it represent a variable or the start of alternative parts, you can either place it within quotes, as in "{", or you can use {@Token(CurlyBrace)}. To capture any bracket (such as { or [, etc) you can use {@Bracket}).

Note: It is much more efficient to use a token category than to define a regex within a pattern. If you need a token with a pattern that's not in the list of tokens in the example, you can define a token with Token.Add, and then refer to it by category in the pattern.

If you do not a rule to interpret commands or token categories, pass it as a string to {@Eval}

Pattern Best Practices & Pitfalls

Designing robust patterns in uCalc requires a shift from traditional "string-matching" thinking to "structural-parsing" thinking. While uCalc provides powerful regex-like capabilities, its integration with the expression engine allows for more maintainable logic.

Best Practices

1. Favor Specificity over Generality

The more specific your pattern, the less the engine has to backtrack.

2. Use Descriptive Pattern Names

When defining custom patterns or utilizing sub-patterns, use names that reflect the intent of the data, not its format.Instead of Pattern1, use EmailAddress or ProductCode.

Common Pitfalls

1. The "Greedy" Trap

By default, some tokens may consume more than intended. Always verify if a "Lazy" match (stopping at the first possible opportunity) is required.

2. Deep Recursion

Patterns that call themselves or are nested too deeply can lead to stack overflows or performance degradation. Ensure recursive patterns have a clear "Base Case" or exit condition.

3. Ignoring Whitespace

In many parsing scenarios, (space), \t (tab), and \n (newline) are critical. Use {@Whitespace} to explicitly capture these when needed.

Examples