Cody

# Problem 2811. Regex match

Solution 2866658

Submitted on 22 Aug 2020
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
userinput = '2015'; pattern = '[0-9]+'; isvalid = true; assert(isequal(regex_match(userinput, pattern), isvalid))

Undefined variable userinput. Error in regex_match>@(i)isequal(length(char(temp{i})),length(userinput{i})) (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in regex_match (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in Test1 (line 4) assert(isequal(regex_match(userinput, pattern), isvalid))

2   Fail
userinput = '2015b'; pattern = '[0-9]+'; isvalid = false; assert(isequal(regex_match(userinput, pattern), isvalid))

Undefined variable userinput. Error in regex_match>@(i)isequal(length(char(temp{i})),length(userinput{i})) (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in regex_match (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in Test2 (line 4) assert(isequal(regex_match(userinput, pattern), isvalid))

3   Fail
userinput = {'BA63RDCL' 'BD51SMR', 'YK02OML', 'TA71AAL', ' BD51GHJ ', 'GX62PTL', 'IQ14ZXY'}; pattern = '[A-HK-PR-WY][A-Y](51|(0|5)[2-9]|(1|6)[0-4])[A-Z]{3}'; isvalid = [false true true false false true false]; assert(isequal(regex_match(userinput, pattern), isvalid))

Undefined variable userinput. Error in regex_match>@(i)isequal(length(char(temp{i})),length(userinput{i})) (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in regex_match (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in Test3 (line 4) assert(isequal(regex_match(userinput, pattern), isvalid))

4   Fail
userinput = {'Alan Smith', '05 12 1962', 'AB123456C'}; pattern = {'([A-Z][a-z]+ )+([A-Z][a-z]+)', '(0[1-9]|[12][0-9]|3[01]) (0[1-9]|1[0-2]) (19[0-9]{2}|200[0-9]|201[0-4])', '[A-CEGHJ-PRST-W-Z][A-CEGHJ-NPRST-W-Z][0-9]{6}[A-D]'}; isvalid = [true true true]; assert(isequal(regex_match(userinput, pattern), isvalid))

Undefined variable userinput. Error in regex_match>@(i)isequal(length(char(temp{i})),length(userinput{i})) (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in regex_match (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in Test4 (line 4) assert(isequal(regex_match(userinput, pattern), isvalid))

5   Fail
userinput = {'A1an Smith', '05 12 1962 2', 'NT987654A'}; pattern = {'([A-Z][a-z]+ )+([A-Z][a-z]+)', '(0[1-9]|[12][0-9]|3[01]) (0[1-9]|1[0-2]) (19[0-9]{2}|200[0-9]|201[0-4])', '[A-CEGHJ-PRST-W-Z][A-CEGHJ-NPRST-W-Z][0-9]{6}[A-D]'}; isvalid = [false false true]; assert(isequal(regex_match(userinput, pattern), isvalid))

Undefined variable userinput. Error in regex_match>@(i)isequal(length(char(temp{i})),length(userinput{i})) (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in regex_match (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in Test5 (line 4) assert(isequal(regex_match(userinput, pattern), isvalid))

6   Fail
userinput = 'BD51SMR'; pattern = {'[0-9]+', '[A-HK-PR-WY][A-Y](51|(0|5)[2-9]|(1|6)[0-4])[A-Z]{3}', '([A-Z][a-z]+ )+([A-Z][a-z]+)'}; isvalid = [false true false]; assert(isequal(regex_match(userinput, pattern), isvalid))

Undefined variable userinput. Error in regex_match>@(i)isequal(length(char(temp{i})),length(userinput{i})) (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in regex_match (line 3) arrayfun(@(i) isequal(length(char(temp{i})), length(userinput{i})), 1:length(temp)) Error in Test6 (line 4) assert(isequal(regex_match(userinput, pattern), isvalid))

7   Pass