2 ms·
The question was: Write a method that can take in a regex and a string and return whether the string matches it, with the regex limited to the characters . * ?
by lazyasciiart 8y ago
The question was: Write a method that can take in a regex and a string and return whether the string matches it, with the regex limited to the characters . * ?
(And backtracking is definitely where I started coming unstuck)
- senorsmile 8y agoAh, that's definitely different than I understood your first post. You're writing a regex to match a given type of string. The regex parser is in the language itself, consuming what you've written and evaluating it.
- lazyasciiart 8y agoNo, I was writing the regex parsing code. The regex was one of the inputs.
- thijsvandien 8y agoIf the regex is really just a sequence of dots followed by a question mark, asterisk or nothing, thus cannot contain literals, the only thing you need to check for is the length of the string. The minimum length will be the number of dots without a quantifier (i.e. exactly one character). If there is any dot followed by an asterisk, there is no maximum length. Otherwise, the maximum length will be the minimum length plus the number of dots followed by a question mark. Writing the code for this is left as an exercise to the reader. ;)
- lazyasciiart 8y agoThe regex can be any string made up of any number of those three characters in any order.