Grokking Microsoft Coding Interview
Ask Author
Back to course home

0% completed

Vote For New Content
Regular Expression Matching (hard)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

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

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible