Skip to content

fix: use raw strings for regex patterns in Lesson 6.1 grading#149

Open
Maanik23 wants to merge 1 commit intoanthropics:masterfrom
Maanik23:fix/lesson-6.1-regex-syntax
Open

fix: use raw strings for regex patterns in Lesson 6.1 grading#149
Maanik23 wants to merge 1 commit intoanthropics:masterfrom
Maanik23:fix/lesson-6.1-regex-syntax

Conversation

@Maanik23
Copy link
Copy Markdown

@Maanik23 Maanik23 commented Apr 4, 2026

Fixes #103

Summary

The REGEX_CATEGORIES dictionary in Exercise 6.1 uses backslash-escaped parentheses (e.g., "A\) P") as regex patterns. Without the r prefix, Python interprets \) as an invalid escape sequence, raising SyntaxWarning in Python 3.12+ and potentially causing DeprecationWarning in earlier versions.

Changes

Added the r (raw string) prefix to all four regex pattern strings in REGEX_CATEGORIES across all three tutorial variants:

# Before
REGEX_CATEGORIES = {
    "A": "A\) P",
    ...
}

# After
REGEX_CATEGORIES = {
    "A": r"A\) P",
    ...
}

Files changed:

  • prompt_engineering_interactive_tutorial/Anthropic 1P/06_Precognition_Thinking_Step_by_Step.ipynb
  • prompt_engineering_interactive_tutorial/AmazonBedrock/anthropic/06_Precognition_Thinking_Step_by_Step.ipynb
  • prompt_engineering_interactive_tutorial/AmazonBedrock/boto3/06_Precognition_Thinking_Step_by_Step.ipynb

Test plan

  • Verified all three notebooks have the fix applied
  • Fix is consistent across Anthropic 1P, AmazonBedrock anthropic, and AmazonBedrock boto3 variants
  • Only the REGEX_CATEGORIES in Exercise 6.1 is affected (Exercise 6.2 uses XML tag patterns which don't need escaping)

The REGEX_CATEGORIES dict in Exercise 6.1 uses backslash-escaped
parentheses (e.g., "A\) P") which triggers Python SyntaxWarning for
invalid escape sequences. Adding the r prefix makes them proper raw
strings so the regex engine receives the intended patterns.

Fixed across all three tutorial variants: Anthropic 1P, AmazonBedrock
anthropic, and AmazonBedrock boto3.

Fixes anthropics#103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lesson 6.1 grading syntax error

1 participant