Your question is Regex Match Function. Start with the requirements on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Amplify Life Center QA checks may need to determine whether a text value contains a pattern. Implement a simplified regular-expression matcher that returns True when the pattern matches any contiguous substring of the text.
The pattern supports:
. which matches any single character.* which matches zero or more occurrences of the immediately preceding literal or . token.The entire pattern does not need to match the entire text. For example, cat matches a cat record.
Implement contains_regex(text, pattern), where both inputs are strings. Return a boolean. The pattern is guaranteed to be valid, and * never appears without a preceding token.
Example 1
Input: text = "A member completed onboarding", pattern = "completed.*boarding"
Output: True
The pattern matches the substring completed onboarding.
Example 2
Input: text = "Amplify QA review", pattern = "q.a"
Output: True
The pattern matches Q followed by any character and A, case-sensitive matching permitting the exact substring QA only if the pattern is adjusted for the intervening character. Here, q.a does not match because uppercase and lowercase characters differ.
., and *.* applies only to the immediately preceding token.def contains_regex(text, pattern):