The title is pretty explicit and below are couple of samples input/output. Note that the regexps used are supposed to match from beginning to end of the string.
'abc' =~ 'abc' (match)
'abc' =~ 'a*bc' (match)
'aaaaaaabc' =~ 'c*bc' (no match)
'aaaaaaabc' =~ 'a.*bc' (match)
'abbbbaaaaaabc' =~ 'ab*a*b*c' (match)
'abbbbaaaaaabc' =~ 'ab*a*h*bc' (match)
'bbd' =~ 'b*bbd' (match)
'bbd' =~ '.*bbd' (match)
'bbd' =~ '.*cbd' (no match)
'' =~ '.*' (match)
My implementation for this is located at:
https://github.com/jpbillaud/piexposed/blob/master/string/string_match_regexp.c
Now I was wondering if anybody would think about a more interesting way to solve this using DP, Finite Automata or whatever else.
Take a look at this implementation of a regular expression matcher by Rob Pike, taken from the book The Practice of Programming. It’s absolutely beautiful code, in just 35 lines of C it happens to meet all the requirements in the question (and a bit more!). Quoting from the article referenced above: