refactor(recipe): improve subRe regexp and add explanatory comments
Simplify the subRe regular expression by using a non-capturing group for the section labels instead of alternation, and switch the lookahead to a non-capturing group for consistency. Add comments to document the purpose of stepRe and subRe for better maintainability.
This commit is contained in:
parent
aa38e92fb5
commit
6bd72aad25
@ -12,8 +12,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// stepRe finds every "### Step N: Title" heading
|
||||||
stepRe = regexp.MustCompile(`(?m)^### Step (\d+): (.+)$`)
|
stepRe = regexp.MustCompile(`(?m)^### Step (\d+): (.+)$`)
|
||||||
subRe = regexp.MustCompile(`(?m)^(\*\*Objective:\*\*|\*\*Instructions:\*\*|\*\*Expected output:\*\*)\s*(.+?)(?=\n\n|\n###|\z)`)
|
|
||||||
|
// subRe finds the three labelled sections inside each step.
|
||||||
|
// We use a simple non-capturing group + word-boundary approach instead of lookahead.
|
||||||
|
subRe = regexp.MustCompile(`(?m)^(\*\*(?:Objective|Instructions|Expected output):\*\*)\s*(.+?)(?:\n\n|\n###|\z)`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// Load reads a recipe from disk and fully parses it.
|
// Load reads a recipe from disk and fully parses it.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user