Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%% validate integer
userinput = '2015';
pattern = '[0-9]+';
isvalid = true;
assert(isequal(regex_match(userinput, pattern), isvalid))
|
2 | Pass |
%% validate integer
userinput = '2015b';
pattern = '[0-9]+';
isvalid = false;
assert(isequal(regex_match(userinput, pattern), isvalid))
|
3 | Pass |
%% validate modern UK number plate (up to 2014)
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))
|
4 | Pass |
%% validate various fields (name, dob, UK national insurance number)
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))
|
5 | Pass |
%% validate various fields (name, dob, UK national insurance number)
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))
|
6 | Pass |
%% validate string against several regexp. Is it a number, a reg. plate, or a name?
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))
|
7 | Pass |
%% no java
user_solution = fileread('regex_match.m');
assert(isempty(strfind(user_solution,'java')));
|
Check to see if a Sudoku Puzzle is Solved
279 Solvers
Rotate and display numbered tile
239 Solvers
110 Solvers
123 Solvers
The sum of the numbers in the vector
426 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!