liveBook · Manning

Regular expression

As explained in LLM Evaluation and Alignment, The Foundational Ideas

A regular expression is a pattern language for matching, extracting, or validating character sequences in text.

A regular expression (RegEx) is a pattern language for matching text. In answer extraction, it searches generated responses for common answer patterns after free-form generation. section 1.1.1

Regex can make variable model outputs easier to evaluate, but it is brittle: a numeric pattern may capture an intermediate calculation instead of the final answer. section 1.1.1

Extracting a numerical answer

A response may contain “= 1,680 - 84 = 1,596” or explanatory text such as “The answer is 1,596.” A regex intended to extract numbers can select the wrong occurrence. section 1.1.1

Prefer structured outputs or constrained decoding when reliable extraction matters; these approaches reduce dependence on post-processing free-form text. section 1.1.1

How LLM Evaluation and Alignment, The Foundational Ideas covers it

How deep it goes
Defines regex as a traditional extraction method and diagnoses brittleness, but provides no implementation details.
Examples
Shows numerical extraction from explanatory calculations and chain-of-thought responses.
What you can do after
Diagnose why regex-based answer extraction can capture intermediate values instead of intended final answers.
How it connects
Connects regular expressions with chain-of-thought, post-processing, structured outputs, and constrained decoding.

Also explained in

Compare how 32 books explain regular expression →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of LLM Evaluation and Alignment, The Foundational Ideas. The section links point to the parts of the book it draws on.