Regex & Rule Based ChatBots
What are we trying to accomplish?
In this module, students will learn how pattern matching enables computers to understand and respond to human language in a structured, predictable way. By combining regular expressions (regex) with rule-based chatbot design, students will build conversational systems that can interpret user intent, control conversation flow, and deliver deterministic responses.
This module serves as a foundational bridge between traditional programming logic and more advanced conversational systems. Students will gain hands-on experience transforming free-form user input into structured meaning—an essential skill for building chatbots, form validators, command-line tools, and customer service automation. By the end of this module, students will understand both the power and limitations of rule-based conversational systems and be prepared to transition into data-driven and AI-based chatbots.
Lectures & Assignments
Lectures
Assignments
TLO's (Terminal Learning Objectives)
- Design and implement a functional rule-based chatbot using Python
- Apply regular expressions to detect intent from unstructured user input
- Build a controlled conversation loop with clear entry and exit conditions
- Map user input patterns to deterministic chatbot responses
- Debug and refine conversational logic by testing rule execution paths
- Explain when rule-based chatbots are appropriate and when they are not
ELO's (Enabling Learning Objectives)
- What regular expressions are and how they enable pattern matching in text
- How regex differs from simple string comparison
- How conversational intent can be inferred without machine learning
- The relationship between rules, patterns, and responses
- Why input normalization (lowercasing, stripping whitespace) is critical
- The limitations of deterministic systems in handling natural language
- How rule-based chatbots compare to retrieval-based and generative chatbots
- How real-world customer service bots use layered rule systems for compliance and reliability