Design Gurus Logo
Regular Expression Matching (hard)

Problem Statement

Given a string text and regular expression pattern, return true if string text matches with pattern. Otherwise, return false.

Follow the below rules to match text with pattern.

  • '.' matches any single character.
  • '*' matches zero or more occurrences of the preceding element.

Examples

  • Example 1:

    • Input: text = "abc", pattern = "a.c"
    • Expected Output: true
    • Justification: The '.' in the pattern matches any character, so "a.c" matches "abc".
  • Example 2:

    • Input: text = "aadg", pattern = ".*d."
    • Expected Output: true
    • Justification: The pattern ".*d." matches any string that contains "d" followed by any character, which "aadg" does.
  • Example 3:

    • Input: text = "hello", pattern = "he*o"
    • Expected Output: false
    • Justification: The string 'hello' doesn't match the pattern "he*o" as the pattern referes to strings like "heo", "heeo", "heeeo", etc.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Unlock this and all other premium problems.
No code editor for this lesson
This lesson focuses on concepts and theory