Basic regular expression matching · Compiler

Basic regular expression matching

Match the pattern against the entire text. A lowercase letter matches itself, a dot matches any one letter, and a star after either allows zero or more repetitions of that element. The pattern contains exactly one dot followed by a star (.*). Among all full matches, find the greatest number of letters that this .* can consume.

Input
The first line contains the text, a word of 1 to 40 lowercase English letters. The second line contains a pattern of 2 to 40 characters made of lowercase English letters and dots, each optionally followed by one star. Exactly one starred element is a dot.
Output
Print the maximum number of letters consumed by .* in a full match, or -1 if no full match exists.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…