diff --git a/DailyCodingProblem/implement_regex.py b/DailyCodingProblem/implement_regex.py index 7f337e4..d285f33 100644 --- a/DailyCodingProblem/implement_regex.py +++ b/DailyCodingProblem/implement_regex.py @@ -11,12 +11,28 @@ expression and returns whether or not the string matches the regular expression. -For example, given the regular expression "ra." and the string "ray", -your function should return true. The same regular expression on the -string "raymond" should return false. +part - 1 : + For example, given the regular expression "ra." and the string "ray", + your function should return true. The same regular expression on the + string "raymond" should return false. -Given the regular expression ".*at" and the string "chat", your function -should return true. The same regular expression on the string "chats" -should return false. -""" \ No newline at end of file +part - 2: + Given the regular expression ".*at" and the string "chat", your function + should return true. The same regular expression on the string "chats" + should return false. + +""" + +#part - 1 solution +def regex_match1(string,regex): + v = regex.split('.') + if v[0] != '': + t = v[0] + else: + t = v[1] + if (string.startswith(t) or string.endswith(t)): + if len(string) == len(t) + 1: + return 'true' + return 'false' + return 'false' \ No newline at end of file