Regular Expression Matching
Detailed guide and Python implementation for the 'Regular Expression Matching' problem.
Problem Statement
Given an input string s and a pattern p, implement regular expression matching with support for '.' and '*' where:
- '.' Matches any single character.
- '*' Matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
Write a function isMatch(s: str, p: str) -> bool.
- •1 <= len(s) <= 20
- •1 <= len(p) <= 20
- •s contains only lowercase English letters.
- •p contains only lowercase English letters, '.', and '*'.
- •It is guaranteed for each appearance of the character '*', there will be a previous valid character to match.
Examples
s = "aa", p = "a"
False
"a" does not match the entire string "aa".
s = "aa", p = "a*"
True
'*' repeats the preceding 'a' once to match "aa".
s = "ab", p = ".*"
True
".*" matches zero or more of any character.
Need a Hint?
Edge Cases to Watch
- Empty input structures
- Single element inputs
- Large numerical bounds
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Use Regular Expressions
Master Python regular expressions using the built-in re module. Learn string matching, pattern searching, finding all occurrences, and text replacement.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.